第一种函数视图
from django.contrib.auth.decorators import login_required
在函数视图上加入
@login_required
第二种类视图
from django.contrib.auth.decorators import login_required from django.utils.decorators import method_decorator class FooView(View): @method_decorator(login_required) def get(request, *args, **kwargs): return HttpResponse("hello world")