GrantU
GrantU

Reputation: 6555

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.

Upvotes: 7

Views: 1264

Answers (1)

Nicolas Cortot
Nicolas Cortot

Reputation: 6701

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.

Upvotes: 11

Related Questions