0

我希望以 HTML 格式呈现一个 html 序列,而不是将其显示为字符串。

视图.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>

而我希望它看起来像这样 -

请点击以下链接对应用程序进行授权 - [Authorize!][1]

任何想法,我都可以做一些调整以将字符串呈现为 html。

PS:我知道render并且render_to_response

4

1 回答 1

0

您需要在模板中使用|safe过滤器

要不就

return HttpResponse(safe(escape(ret_html)))

建议使用renderrender_to_response

于 2013-08-22T16:38:21.597 回答