Python 将httpresponse对象呈现为html
我希望html序列以html格式呈现,而不是以字符串形式显示 Views.py-Python 将httpresponse对象呈现为html,python,django,django-views,Python,Django,Django Views,我希望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>
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))
从django.utils.html导入转义
ret_html=“”请单击以下链接
要授权应用程序-“”“
返回HttpResponse(转义(ret_html))
在浏览器中,上述内容的呈现方式与此完全相同-
<p> Please click the following link to authorize the application - <a href='/social/addtwitter/' target='_blank'>Authorize!</a> </p>
请单击以下链接以授权该应用程序-
而我希望它看起来像这样-
请单击以下链接授权应用程序-[授权!][1]
任何想法,我都可以做一些调整,将字符串呈现为html
PS:我知道渲染
和渲染到响应
您需要在模板中使用
或者只是
return HttpResponse(safe(escape(ret_html)))
建议使用render
或render\u to\u response
您需要将其标记为安全: