0
我想要一個HTML序列在HTML中呈現,而不是以字符串形式顯示。將一個httpresponse對象渲染爲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
您需要將其標記爲安全:https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.html.es海角 –