How to disable Django's CSRF validation?

前端 未结 9 1341
梦毁少年i
梦毁少年i 2020-11-30 21:23

I have commented out csrf processor and middleware lines in settings.py:

122 
123 TEMPLATE_CONTEXT_PROCESSORS = (
124     \'django.contrib.auth.         


        
9条回答
  •  天命终不由人
    2020-11-30 22:10

    The answer might be inappropriate, but I hope it helps you

    class DisableCSRFOnDebug(object):
        def process_request(self, request):
            if settings.DEBUG:
                setattr(request, '_dont_enforce_csrf_checks', True)
    

    Having middleware like this helps to debug requests and to check csrf in production servers.

提交回复
热议问题