[API] Send csrf token and retrieve with javascript?

已查看 127 次
跳至第一个未读帖子

Alexandro Gonçalves Dos Santos

未读,
2020年9月30日 19:40:422020/9/30
收件人 Django users
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 posts.py file looks like this:
```python
from django.http import HttpResponse
from django.views.decorators.csrf import ensure_csrf_cookie

@ensure_csrf_cookie
def index(request):
return HttpResponse('ok')
```

The header I get when accessing the route 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
```

Thanks for the help.

Alexandro Gonçalves Dos Santos

未读,
2020年9月30日 19:40:442020/9/30
收件人 Django users
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 posts.py file looks like this:
```python
from django.http import HttpResponse
from django.views.decorators.csrf import ensure_csrf_cookie

@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.

RANGA BHARATH JINKA

未读,
2020年10月1日 00:17:392020/10/1
收件人 django...@googlegroups.com
Hi,

   Check the docs link. This will be useful. All the best

--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fd412572-d35c-460e-934f-6fb684d1c0c9n%40googlegroups.com.


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

Dvs Khamele

未读,
2020年10月11日 13:26:462020/10/11
收件人 django...@googlegroups.com、alexand...@gmail.com
Hi do you hire contract based python/django freelancer?
 We can help you in this and related techincal tasks at fair prices. Reply or send email to div...@pythonmate.com
Best Regards, 
Divyesh Khamele,
Pythonmate


--
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 django-users...@googlegroups.com.
回复全部
回复作者
转发
0 个新帖子