[Django]-Error: “CSRF verification failed. Request aborted.” when using jquery json with Django

1👍

This error is raised, when you try to post data outer than a django form.

The simple, but UNSAFE method is to add @csrf_exempt before your views, like:

@csrf_exempt
def my_view(request):
    pass

The not that simple method is written here: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax

2👍

This is the solution i found:

from django.views.decorators.csrf import csrf_exempt

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

Leave a comment