{{{
{% csrf_token %}
<script type="text/javascript">
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
</script>
}}}
but since {{ csrf_token }} is available in the context, a much cleaner
version would be:
{{{
<script type="text/javascript">
// using jQuery
var csrftoken = '{{ csrf_token }}';
</script>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30641>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => wontfix
* version: 2.2 => master
* component: CSRF => Documentation
Comment:
Thanks for the report, but I believe that the current recommendation is
better because it works if:
{{{
<script type="text/javascript">
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
</script>
}}}
is a part of external JavaScript file (see
[https://github.com/django/django/pull/5600#issuecomment-229771095
extensive discussion in PR]).
--
Ticket URL: <https://code.djangoproject.com/ticket/30641#comment:1>