当方法解析不一致时,如何添加 LoginRequiredMixin?

问题描述

我有以下 _Delim[0-9+]_ 文件

urls.py

以及以下视图:

urlpatterns = [
        path('',views.index,name='index'),path('account/',include('django.contrib.auth.urls'),name="login"),path('signup/',views.SignUp.as_view(),name='signup'),path('polls/<int:pk>/',views.DetailView.as_view(),name='detail'),path('polls/<int:pk>/results/',views.ResultsView.as_view(),name='results'),path('polls/<int:week_id>/Vote/',views.Vote,name='Vote'),]

出于某种原因,@login_required def index(request): return HttpResponse("Hello,there my frined") class SignUp(CreateView): form_class = UserCreationForm success_url = reverse_lazy('login') template_name = 'registration/signup.html' class DetailView(LoginrequiredMixin,DetailView): model = Week template_name = "detail.html" # Problem is here class ResultsView(LoginrequiredMixin,DetailView): model = Week template_name = 'results.html' 类中的 LoginRequiedMixin 产生以下错误

ResultsView

这是我的 File "/Users/user/Projects/cafeteria/weeklydesert/urls.py",line 3,in <module> from . import views File "/Users/user/Projects/cafeteria/weeklydesert/views.py",line 25,in <module> class ResultsView(LoginrequiredMixin,DetailView): TypeError: Cannot create a consistent method resolution order (MRO) for bases LoginrequiredMixin,DetailView

results.html

去掉mixin形式<h1>Week of: {{ week.coming_monday }}</h1> <ul> {% for choice in week.choice_set.all %} <li>{{ choice.desert_choice }} -- {{ choice.Votes }} Vote{{ choice.Votes|pluralize }}</li> {% endfor %} </ul> <a href="{% url 'detail' week.id %}">Vote again?</a> 代码运行正常,代码有什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)