Wednesday, September 30, 2020

Send csrf token and retrieve with javascript?

I am building a django api to be used in a front end of another server, how do I send the csrf token and how do I retrieve it in the front end with javascript?

Currently my file looks like this:
from django.http import HttpResponse
from django.views.decorators.csrf import ensure_csrf_cookie

def index(request):
return HttpResponse('ok')

And the header that the javascript receives when making the request is:
content-length: 2
content-type: text/html; charset=utf-8
date: Wed, 30 Sep 2020 22:37:40 GMT
server: WSGIServer/0.2 CPython/3.7.3
vary: Cookie
x-content-type-options: nosniff
x-frame-options: DENY

Thank you so much for your help.

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment