Anna Taylor
Anna Taylor

Reputation: 467

Render Markdown to HTML in Django templates

I would like to render Markdown to HTML so that I could simply write markdown inside my HTML templates.

Example: home.html:

#This is a simple markdown in HTML

And I would like Django to interpret my Markdown and display it as if it was HTML:

<h1> This is a simple markdown in HTML </h1>

What would be the easiest way to implement it?

Upvotes: 11

Views: 13384

Answers (1)

Rohan Thacker
Rohan Thacker

Reputation: 6357

In order to do this, one would need to create a template filter that converts the Markdown text into HTML for the template.

Fortunately this is a common task and there are multiple packages that can help you.

Django Package - For use with django

Python Markdown - Python Markdown that you can use within the custom Django template filter

Upvotes: 15

Related Questions