How to disable Django's CSRF validation?

前端 未结 9 1318
梦毁少年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:14

    To disable CSRF for class based views the following worked for me.
    Using django 1.10 and python 3.5.2

    from django.views.decorators.csrf import csrf_exempt
    from django.utils.decorators import method_decorator
    
    @method_decorator(csrf_exempt, name='dispatch')
    class TestView(View):
        def post(self, request, *args, **kwargs):
            return HttpResponse('Hello world')
    

提交回复
热议问题