When creating a HTML form using Django format_html, I need to insert the csrf_token
at the place of {% csrf_token %}
below, since the use of {% csrf_token %}
of course don't substitute when using format_html
:
res = format_html('''
<form method="POST">
{% csrf_token %}
{}
</form>''', ...
How do I manually generate the equivalent of {% csrf_token %}
which is inserted when rendering a HTML template by Django?
Copyright Notice:Content Author:「EquipDev」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33360708/how-to-add-csrf-token-to-manually-created-html-form