Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render markdown content with jinja2, in a django project?

I am working on a django project with a model like:

class Article(models.Model):
    ...
    # which is submitted by users through a markdown editor.
    content = models.TextField(_('content'), blank=True)
    ...

As a result, I render the content in the templates with Jinja2, what I get is only raw markdown content without any style.

like image 203
Foxjack Avatar asked Nov 30 '22 11:11

Foxjack


1 Answers

Not sure about Django, but I use Markdown with Jinja2 in flask. I initialize Markdown when the app runs like this.

app

from flask.ext.markdown import Markdown
md = Markdown(app, extensions=['fenced_code'])

Then I add the filter to the template.

template

<H2>{{ post.title }}</H2>
{{post.body|markdown}}

In short, do you have the template filter set?

like image 69
jwogrady Avatar answered Dec 05 '22 12:12

jwogrady