Alex
Alex

Reputation: 193

How to render string literal with html tags in django?

I've wrote a custom view to parse markdown files using regex and I'm passing content as a string literal to the template

context = "Django is a web framework written using <a href='https://www.python.org/'>Python</a>"

return render(request, "blog/post.html", {"context": context})

And in template:

<p>{{ context }}</p>

But the engine renders content as a plain text. How to make links to be links and paragraphs to be paragraphs?

Upvotes: 0

Views: 1821

Answers (1)

Ahtisham
Ahtisham

Reputation: 10106

Just add safe template tag like @markwalker_ said in comments it will turn off autoescape of html tags.

 <p>{{ context|safe }}</p>

Upvotes: 2

Related Questions