django html 转义

django 默认html是转义的。

在view.py 定义一段html字符串,在html接收

在html接收

显示结果是:

查看源码得知:

 他默认将<>转成对于的&lt; &gt;

< 会转换为&lt;

> 会转换为&gt;

' (单引号) 会转换为&#39;

" (双引号)会转换为 &quot;

& 会转换为 &amp;

默认转义可以用过滤器:
escape

关闭转义 safe
代码块转义:
{ % autoescape off %}
{{ body }}
{ % endautoescape %}

效果:

 

猜你喜欢

转载自www.cnblogs.com/mawenwen/p/9338261.html