Skip to content

Instantly share code, notes, and snippets.

@metatoaster
Created July 26, 2013 15:06
Show Gist options
  • Save metatoaster/6089625 to your computer and use it in GitHub Desktop.
Save metatoaster/6089625 to your computer and use it in GitHub Desktop.
Quickie flask app
"""
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