Skip to content

Instantly share code, notes, and snippets.

@sloria
Created July 15, 2013 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sloria/6004206 to your computer and use it in GitHub Desktop.
Save sloria/6004206 to your computer and use it in GitHub Desktop.
from flask import render_template
from app import app, pages
@app.route('/')
def home():
posts = [page for page in pages if 'date' in page.meta]
# Sort pages by date
sorted_posts = sorted(posts, reverse=True,
key=lambda page: page.meta['date'])
return render_template('index.html', pages=sorted_posts)
@app.route('/<path:path>/')
def page(path):
# `path` is the filename of a page, without the file extension
# e.g. "first-post"
page = pages.get_or_404(path)
return render_template('page.html', page=page)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment