Created
July 26, 2013 15:06
-
-
Save metatoaster/6089625 to your computer and use it in GitHub Desktop.
Quickie flask app
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
""" | |
Instructions: (save this file as app.py or whatever) | |
$ virtualenv .env | |
$ . .env/bin/activate | |
(.env) $ pip install flask | |
(.env) $ python app.py | |
""" | |
import json | |
from flask import Flask, render_template_string | |
raw = '''{ | |
"url": ["http://example.com", "http://example.net"] | |
} | |
''' | |
template = """<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test page</title> | |
</head> | |
<body> | |
<dl> | |
<dt>The following are the urls</dt> | |
<dd> | |
<ul> | |
{% for url in data.get('url') %} | |
<li>{{ url }}</li> | |
{% endfor %} | |
</ul> | |
</dd> | |
</dl> | |
</body> | |
</html> | |
""" | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
data = json.loads(raw) | |
return render_template_string(template, data=data) | |
app.run(port=8880) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment