我从转发服务器获得响应:
'item':'<b> Some Data </b>'
我将此类数据传递给使用item= json.loads(response)
默认情况下,django模板(在Google App Engine中)进一步逃避,
所以它的双重逃脱了结果。
我可以使用safe
删除一个级别的转义,如:
{{item|safe}}
如何将实体转换为相应的符号?
答案 0 :(得分:4)
你可以这样做:
{% autoescape off %}
{{ your_text_var }}
{% endautoescape %}
答案 1 :(得分:-2)
警告 - 这不是推荐的解决方案。您应该使用自动转换(检查Rafael's answer)。
以下应该做的工作
response.replace('&', '&').replace('<', '<').replace('>', '>')
更新 -
在Jan Schär提出建议后,您应该使用以下内容:
response.replace('<', '<').replace('>', '>').replace('&', '&')
因为,如果response
为&gt;
,则会产生>
而不是正确的>
。您应该在最后解析&
。