开发者

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 :

&amp;lt;p&amp;gt;&amp;lt;label for=&amp;quot;id_username&amp;quot;&amp;gt;Utilisateur:&amp;lt;/label&amp;gt; &amp;lt;input autocomplete=&amp;quot;off&amp;quot; id=&amp;quot;id_username&amp;quot; type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; maxlength=&amp;quot;100&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;label for=&amp;quot;id_password&amp;quot;&amp;gt;Mot de passe:&amp;lt;/label&amp;gt; &amp;lt;input autocomplete=&amp;quot;off&amp;quot; type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot; id=&amp;quot;id_password&amp;quot; /&amp;gt;&amp;lt;/p&amp;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 }}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜