我希望用HTML呈现html序列,而不是将其显示为字符串。
Views.py -
from django.utils.html import escape
ret_html = """<p> Please click the following link
to authorize the application - <a href='""" + auth_url + """' target='_blank'>Authorize!</a> </p>"""
return HttpResponse(escape(ret_html))
以上内容在浏览器中完全呈现 -
<p> Please click the following link to authorize the application - <a href='/social/addtwitter/' target='_blank'>Authorize!</a> </p>
而我希望它看起来像这样 -
请点击以下链接授权申请 - [授权!] [1]
任何想法,我都可以做一些调整来将字符串渲染为html。
PS:我知道render
和render_to_response
答案 0 :(得分:0)
您需要使用模板中的|safe
filter
或者只是
return HttpResponse(safe(escape(ret_html)))
建议使用render
或render_to_response