Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render Markdown to HTML in Django templates

Tags:

django

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?

like image 542
Anna Taylor Avatar asked Mar 02 '23 11:03

Anna Taylor


1 Answers

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

like image 138
Rohan Thacker Avatar answered Mar 05 '23 16:03

Rohan Thacker