Ram Kumar
Ram Kumar

Reputation: 590

render a django template from database html contents

I have raw html saved in my database contents. I want that to render that content, following is the way, I try -

    from django.template import Context, Template
    l = MyModel.objects.get(slug=current_slug)
    tpl = Template(escape(l.content_text))
    return HttpResponse(tpl.render(Context({})))

This renders html as string, and in the template I see <html>.....</html> instead of the rendered content.

Let me know, how this can be fixed. Thanks.

Upvotes: 2

Views: 1444

Answers (2)

bruno desthuilliers
bruno desthuilliers

Reputation: 77932

You want mark_safe() not escape().

Upvotes: 1

Paul Draper
Paul Draper

Reputation: 83393

Try removing escape:

tpl = Template(l.content_text)

Upvotes: 0

Related Questions