本章內容html
首頁get方法登陸驗證,方法一django
from django.utils.decorators import method_decorator class IndexView(TemplateView): template_name = "index2.html" #首頁須要登陸驗證,那就須要寫上get方法 @method_decorator(login_required()) def get(self, request, *args, **kwargs): return super(IndexView, self).get(request, *args, **kwargs)
方法二:ui
from django.contrib.auth.mixins import LoginRequiredMixin class IndexView(LoginRequiredMixin, TemplateView): template_name = "index2.html" #這裏再也不須要自定義get的方法了,LoginRequiredMinin方法中實現