django添加装饰器
引入模块:
from django.utils.decorators import method_decorator
添加:@method_decorator(func)
from django.utils.decorators import method_decorator
def outer(func):
def inner(request, *args, **kwargs):
print(request.method)
return func(request, *args, **kwargs)
return inner
class Login(views.View):
@method_decorator(outer)
def get(self, request, *args, **kwargs):
return render(request, 'login.html', {'message': ''})

更多精彩