[Answered ]-Django returning 403 Error β€” "CSRF cookie not set"

2πŸ‘

βœ…

It might be giving this error because you might be having the CSRF protection turned on in middelware settings.

If you don’t need that protection, you can set the view as CSRF exempt.
You can simply use a decorator on the view or you can turn it disable it from middleware settings.

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

@csrf_exempt
def my_view(request):
    return HttpResponse('Hello world')

Leave a comment