Jinja 2 - Django Form : rendering encodes HTML
I was testing Jinja2 in a Django project and have a strange output.
When I render the form, some characters are HTML encoded (< >
etc.)
In the template :
{{ form.as_p() }}
It renders to the browser :
<p><label for="id_username">Utilisateur:</label> <input autocomplete="off" id="id_username" type="text" name="username" maxlength="100" /></p> <p><label for="id_password">Mot de passe:</labe开发者_运维问答l> <input autocomplete="off" type="password" name="password" id="id_password" /></p>
Looking at sources :
&lt;p&gt;&lt;label for=&quot;id_username&quot;&gt;Utilisateur:&lt;/label&gt; &lt;input autocomplete=&quot;off&quot; id=&quot;id_username&quot; type=&quot;text&quot; name=&quot;username&quot; maxlength=&quot;100&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for=&quot;id_password&quot;&gt;Mot de passe:&lt;/label&gt; &lt;input autocomplete=&quot;off&quot; type=&quot;password&quot; name=&quot;password&quot; id=&quot;id_password&quot; /&gt;&lt;/p&gt;
Does anyone know this problem ?
Jinja2 tries to be safe by HTML-escaping the data. So you have to use |safe
filter.
Though I haven't used Django with Jinja2, I believe this should work:
{{ form.as_p()|safe }}
精彩评论