Django中的dispatch方法

class InfoMG(View):
    @method_decorator(csrf_exempt)
    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        return super(InfoMG, self).dispatch(request, *args, **kwargs)

    def get(self, request):
        pass

    def post(self, request):
     pass

简单说作用就是当请求的get或者post的方法之前执行这个dispatch方法,如果定义了什么变量函数都会先执行  

posted @ 2021-08-16 19:26  lucky_tomato  阅读(559)  评论(0编辑  收藏  举报