Flask Snippets

Using the markdown language

Posted by Stephane Wirtel on 2010-05-25 @ 08:07 and filed in Template Tricks

The Markdown language is very useful if you don't know the html language In this snippet, I want to show you how to include this language in your Flask App

The markdown library

easy_install markdown

The code of your Flask application: demo.py

# We import the markdown library
import markdown
from flask import Flask
from flask import render_template
from flask import Markup

app = Flask(__name__)

def index():
  content = """


* Item 1
* Item 2
  content = Markup(markdown.markdown(content))
  return render_template('index.html', **locals())


The Jinja template file: templates/index.html

    <title>Markdown Snippet</title>
    {{ content }}

This snippet by Stephane Wirtel can be used freely for anything you like. Consider it public domain.