Django how to get csrf_token value in the template

django, django-templates, python

Solution

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.

Problem

`{% 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.

Original source