您可以使用
@method_decorator在
dispatch类的方法:
from django.views.generic import Viewfrom django.utils.decorators import method_decoratorfrom django.contrib.auth.decorators import user_passes_testclass MyView(View): @method_decorator(user_passes_test(lambda u: u.is_superuser)) def dispatch(self, *args, **kwargs): return super(MyView, self).dispatch(*args, **kwargs)



