ValueError:关键字参数`name`必须是装饰类的方法名称:

时间:2017-03-02 09:56:00

标签: python django

views.py

from django.shortcuts import render

from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

from briefcase.BaseBriefcaseView import BaseBriefcaseView

from briefcase.models import Customer

@method_decorator(login_required, name='dispatch')
class BriefcaseIndexView(BaseBriefcaseView):
    model = Customer
    template_name = 'briefcase/index.html'

urls.py

from django.conf.urls import url

from briefcase.views import BriefcaseIndexView, invoice_view


urlpatterns = [

    url(r'^$', BriefcaseIndexView.as_view(), name='index'),
    url(r'^index/invoice_view$', invoice_view.as_view(), name='invoice'),

]

BaseBriefcase.py

from cmms.views import DefaultContextView


class BaseBriefcaseView(DefaultContextView):
    extra_context = {}

    def get_context_data(self, **kwargs):
        context = super(BaseBriefcaseView, self).get_context_data(**kwargs)
        context["side_menu"] = self.get_side_menu()
        context["main_menu"] = self.get_main_menu()
        context["side_filter"] = self.get_side_filter()
        context["module"] = "Briefcase"
        return context

我得到的错误是.......

  

ValueError:关键字参数名称必须是方法的名称。 >装饰班:。得到了发送'代替

请帮助django新手。我做错了什么?

1 个答案:

答案 0 :(得分:2)

要将login_required应用于基于类的视图,您应该使用LoginRequiredMixin

class BriefcaseIndexView(LoginRequiredMixin, DefaultContextView):