Initial checkin of stuff that exists so far.

This commit is contained in:
Armin Ronacher 2010-04-06 13:12:57 +02:00
commit 33850c0ebd
15 changed files with 984 additions and 0 deletions

View file

@ -0,0 +1,30 @@
from flask import Flask, abort, redirect, request, session, \
render_template, url_for
#: create a new flask applications. We pass it the name of our module
#: so that flask knows where to look for templates and static files.
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
"""Show an overview page"""
return render_template('index.html')
@app.route('/hello/', methods=['GET', 'POST'])
def hello_user():
"""Ask the user for a name and redirect to :func:`hello`"""
if request.method == 'POST':
return redirect(url_for('hello', name=request.form['name']))
return render_template('hello.html', name=None)
@app.route('/hello/<name>', methods=['GET'])
def hello(name):
"""Greet name friendly"""
return render_template('hello.html', name=name)
if __name__ == '__main__':
app.run(debug=True)

View file

@ -0,0 +1,7 @@
body {
font-family: 'Trebuchet MS', sans-serif;
}
a {
color: #44AD80;
}

View file

@ -0,0 +1,12 @@
{% extends "layout.html" %}
{% block body %}
<p>
This is an example application that shows how
the Werkzeug powered Flask microframework works.
<p>
The various parts of the example application:
<ul>
<li><a href="{{ url_for('hello_user') }}">Hello World</a>
<li><a href="{{ url_for('counter') }}">Counter</a>
</ul>
{% endblock %}

View file

@ -0,0 +1,13 @@
{% extends "layout.html" %}
{% block body %}
{% if name %}
<h2>Hello {{ name }}!</h2>
{% else %}
<h3>Hello Stranger …</h3>
<form action="{{ url_for('hello_user') }}" method="post">
<p>… What's your name?
<p><input type=text name=name size=30>
<input type=submit value="That's me">
</form>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,11 @@
{% extends "layout.html" %}
{% block body %}
<p>
This is an example application that shows how
the Werkzeug powered Flask microframework works.
<p>
The various parts of the example application:
<ul>
<li><a href="{{ url_for('hello_user') }}">Hello World</a>
</ul>
{% endblock %}

View file

@ -0,0 +1,8 @@
<!doctype html>
<title>Flask API Showcase</title>
<link rel=stylesheet href="{{ url_for('static', filename='style.css') }}" type=text/css>
<h1>Flask API Showcase</h1>
{% if request.endpoint != 'index' %}
<div class=backlink><a href="{{ url_for('index') }}">&laquo; back to index</a></div>
{% endif %}
{% block body %}{% endblock %}