[英]render a django template from database html contents
我將原始html保存在數據庫內容中。 我希望它能呈現該內容,以下是我嘗試的方法-
from django.template import Context, Template
l = MyModel.objects.get(slug=current_slug)
tpl = Template(escape(l.content_text))
return HttpResponse(tpl.render(Context({})))
這將html呈現為字符串,並且在模板中,我看到的是<html>.....</html>
而不是呈現的內容。
讓我知道,該如何解決。 謝謝。
您希望mark_safe()
不escape()
。
嘗試刪除escape
:
tpl = Template(l.content_text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.