Categories
Python Answers

How to fix Python Django CSRF Cookie Not Set?

Spread the love

To fix Python Django CSRF Cookie Not Set, we can add the csrf_exempt decorator to our view.

For instance, we write

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt 
def your_view(request):
    if request.method == "POST":
        # do something
    return HttpResponse("Your response")

to apply the @csrf_exempt to the your_view view to make Django ignore the CSRF token check on the view.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *