Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django how to get csrf_token value in the template

{% csrf_token %} outputs a with a form field but, what if I just want the value i..e {{ csrf_token.value }} is this possible? If so how? I have searched online but cannot find any information on how to achieve this.

like image 795
GrantU Avatar asked Dec 29 '13 15:12

GrantU


1 Answers

The csrf_token value is added to the context by django.core.context_processors.csrf, you can use it directly in the template code:

{{ csrf_token }}

This is the value used by the {% csrf_token %} template tag when rendering the form field.

like image 174
Nicolas Cortot Avatar answered Sep 28 '22 07:09

Nicolas Cortot