Last active
December 9, 2015 06:28
-
-
Save tarunbhardwaj/22f7c59781fde287efb5 to your computer and use it in GitHub Desktop.
Render JInja template as static site using Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: avoid loading templates abstract templates.
i.e. template name starts with '_'