forked from orbit-oss/flask
Initial checkin of stuff that exists so far.
This commit is contained in:
commit
33850c0ebd
15 changed files with 984 additions and 0 deletions
30
examples/apishowcase/apishowcase.py
Normal file
30
examples/apishowcase/apishowcase.py
Normal 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)
|
||||
7
examples/apishowcase/static/style.css
Normal file
7
examples/apishowcase/static/style.css
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
body {
|
||||
font-family: 'Trebuchet MS', sans-serif;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #44AD80;
|
||||
}
|
||||
12
examples/apishowcase/templates/counter.html
Normal file
12
examples/apishowcase/templates/counter.html
Normal 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 %}
|
||||
13
examples/apishowcase/templates/hello.html
Normal file
13
examples/apishowcase/templates/hello.html
Normal 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 %}
|
||||
11
examples/apishowcase/templates/index.html
Normal file
11
examples/apishowcase/templates/index.html
Normal 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 %}
|
||||
8
examples/apishowcase/templates/layout.html
Normal file
8
examples/apishowcase/templates/layout.html
Normal 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') }}">« back to index</a></div>
|
||||
{% endif %}
|
||||
{% block body %}{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue