Search code examples
pythondjangocsrfhttplib

httplib - CSRF token


Here's the problem:
I've got a Django site.
I'm trying to send POST request to site with httplib.

When I try to send POST request, Django requires CSRF token.

How can I send POST request without any problems?


Solution

  • Pass the CSRF token to Django, or disable CSRF on the view handling the request.

    from django.views.decorators.csrf import csrf_exempt
    from django.http import HttpResponse
    
    @csrf_exempt
    def my_view(request):
        return HttpResponse('Hello world')