从数据库html内容渲染django模板

时间:2013-12-17 06:49:23

标签: python django django-templates

我的原始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>而不是呈现的内容。

让我知道,如何解决这个问题。谢谢。

2 个答案:

答案 0 :(得分:1)

您希望mark_safe()不是escape()

答案 1 :(得分:0)

尝试删除escape

tpl = Template(l.content_text)
相关问题