Skip to content

Instantly share code, notes, and snippets.

@tarunbhardwaj
Last active December 9, 2015 06:28
Show Gist options
  • Save tarunbhardwaj/22f7c59781fde287efb5 to your computer and use it in GitHub Desktop.
Save tarunbhardwaj/22f7c59781fde287efb5 to your computer and use it in GitHub Desktop.
Render JInja template as static site using Flask
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Jinja2 static site renderer using Flask
@author Tarun Bhardwaj
@license FreeBSD Licence
"""
from flask import Flask, abort, render_template
from jinja2 import TemplateNotFound
app = Flask(__name__)
@app.route("/")
@app.route("/<path>")
def main(path=None):
if not path:
path = 'index.html'
try:
return render_template(path)
except TemplateNotFound:
abort(404)
if __name__ == "__main__":
app.debug = True
app.run()
@tarunbhardwaj
Copy link
Author

TODO: avoid loading templates abstract templates.

i.e. template name starts with '_'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment