Created
May 15, 2013 07:41
-
-
Save dbrandt/5582243 to your computer and use it in GitHub Desktop.
Simple way to test jinja templates. Depends on Flask (and by extension, Jinja2). Copy shell script to the directory where you have the templates you want to test run then execute script and visit localhost:5000/<template_name>
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
#!/bin/bash | |
/bin/chmod 0755 $0 | |
if [ ! -f "jinja_test.py" ]; then | |
cat <<EOF > jinja_test.py | |
import os | |
from flask import Flask, abort, render_template | |
from jinja2 import FileSystemLoader | |
app = Flask(__name__) | |
app.jinja_loader = FileSystemLoader( | |
os.path.dirname(os.path.abspath(__file__))) | |
@app.route("/<tpl>") | |
def test_template(tpl=None): | |
if os.path.exists(tpl): | |
return render_template(tpl) | |
else: | |
abort(404) | |
app.run(debug=True) | |
EOF | |
fi | |
# source ~/bsedev/bin/activate # Uncomment/change if using virtualenv | |
/usr/bin/env python jinja_test.py | |
/bin/rm jinja_test.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment