4π
β
I just got the correct answer .. thanks everybody for helping.
from django.shortcuts import render_to_response
from django.template.context_processors import csrf
def my_view(request):
csrf = unicode(csrf(request)['csrf_token'])
π€Rus Mine
0π
The CSRF token is present in the template rendering context under {{ csrf_token }}
. If you inline the Javascript in a template, you can render it.
<html>
<head>
<script language="JavaScript">
var csrfToken = "{{ csrf_token }}";
</script>
</head>
</html>
Alternative is to access the cookie from javascript (credits Sergio Garcia). The how-to is in his link.
π€Freek Wiekmeijer
- [Django]-How to troubleshoot β ImportError: Could not import settings 'mysite.settings' when deploying django?
- [Django]-Django user profile database problem
- [Django]-Django : 'WSGIRequest' object has no attribute 'user'? β AuthenticationMiddleware & SessionAuthenticationMiddleware are in sequence
- [Django]-Get len of the ArrayField Postgres Django
Source:stackexchange.com