[Fixed]-How do I implement markdown in Django 1.6 app?


Thank you for your answers and suggestions, but I’ve decided to use markdown-deux.

Here’s how I did it:

pip install django-markdown-deux

Then I did pip freeze > requirements.txt to make sure that my requirements file was updated.

Then I added ‘markdown_deux’ to the list of INSTALLED_APPS:


Then I changed my template index.html to:

{% load markdown_deux_tags %}

        <title>My Django Blog</title>
        {% for post in post %}
        <h1>{{ post.title }}</h1>
        <h3>{{ post.pub_date }}</h3>
        {{ post.text|markdown }}
        {{ post.tags }}
        {% endfor %}


Ah, I met with the same problem several months ago, and I found the easiest and most robust solution is to use Github Markdown API.

Here is the code I use for my blog, which I believe will help you more or less. btw I use Python 3 so the encoding part may be different from Python 2.

# generate rendered html file with same name as md
headers = {'Content-Type': 'text/plain'}
if type(self.body) == bytes:  # sometimes body is str sometimes bytes...
    data = self.body
elif type(self.body) == str:
    data = self.body.encode('utf-8')
    print("somthing is wrong")

r = requests.post('https://api.github.com/markdown/raw', headers=headers, data=data)
# avoid recursive invoke
self.html_file.save(self.title+'.html', ContentFile(r.text.encode('utf-8')), save=False)

My code is hosted on github, you can find it here
And My blog is http://laike9m.com.


You may use substitution of old markup implemented here – https://github.com/jamesturk/django-markupfield

Leave a comment