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'
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'),
]
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新手。我做错了什么?
答案 0 :(得分:2)
要将login_required
应用于基于类的视图,您应该使用LoginRequiredMixin
class BriefcaseIndexView(LoginRequiredMixin, DefaultContextView):