当前位置: 移动技术网 > IT编程>脚本编程>Python > django中视图函数中装饰器

django中视图函数中装饰器

2019年11月11日  | 移动技术网IT编程  | 我要评论

歌咏比赛作文,uzcms,重生孔宣

方法一

给指定方法加

from django.utils.decorators import method_decorator

class xx(view):
    @method_decorator(装饰器方法)
    def post(self, request):
                    ...

方法二

给dispatch加

@method_decorator(装饰器方法)
def dispatch(self, request, *args, **kwargs):
    ...

方法三

给类加

from django.utils.decorators import method_decorator
@method_decorator(装饰器方法, name="get")
@method_decorator(装饰器方法, name="post")
class xxxx(view):
    ... 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网