CSRF Middleware - change csrf_token output (from xHTML to HTML)

I have a problem with django csrf middleware ... when I use the csrf_token template tag, I get this output:

<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='6bda3605af31dd8595d2a67d0dda827b' /></div>

but I want this output (HTML is not xHTML:

<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='6bda3605af31dd8595d2a67d0dda827b'></div>

I tried to see the code in the django.middleware.csrf.CsrfViewMiddleware file, but without success :(

So how can I change the output of fo csrf_token?

tanks

+3
source share
3 answers

You need to go and edit django.template.defaulttags.py: On line 48 there is the result of the tag, and you can change it as you want.

, , , - Django !.
, : , , , , "" .

+1

.

{% with csrf_token as csrf_token_clean %}{{ csrf_token_clean }}{% endwith %}

-, HTML, .

<input type="hidden" name="csrfmiddlewaretoken" value="{% with csrf_token as csrf_token_clean %}{{ csrf_token_clean }}{% endwith %}" >

: http://www.phptodjango.com/2010/07/django-csrftoken-template-tag-fix.html

+3

:

<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">

{% with %} .

+3

Source: https://habr.com/ru/post/1730757/


All Articles