Having a POST'able API and Django's CSRF Middleware

前端 未结 3 425
春和景丽
春和景丽 2020-12-08 14:17

I have a Django webapp that has both a front-end, web-accessible component and an API that is accessed by a desktop client. However, now with the new CSRF middleware compon

3条回答
  •  没有蜡笔的小新
    2020-12-08 14:29

    If you are using a Class Based View then you will need to csrf_exempt the dispatch method rather than the post method like this:

    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        return super(MyView, self).dispatch(request, *args, **kwargs)
    

    See this bug ticket: https://code.djangoproject.com/ticket/15794

提交回复
热议问题