Basics¶
Creating basic apps is easy, you just decorate a function with a route and you’re pretty much done.
As a bonus flask comes configured with a few things:
- Built in debugger
- Static file serving
- Templates (Jinja2)
Tests¶
URLs¶
Bonus: You can use the sphinxcontrib-httpdomain’s sphinxcontrib.autohttp.flask extension to automagically generate docs. Note the free static file serving below.
-
GET
/broken
¶ Show off the built in debugger
-
GET
/
¶
-
GET
/static/
(path: filename)¶ Function used internally to send static files from the static folder to the browser.
New in version 0.5.
More Advanced¶
Now to work on the next topic, blueprints. The skeletal app is somewhat similar.
-
pythonie.application.
index
()[source]¶ To see this in action go to http://building-webapps-with-flask.herokuapp.com/
All the URLs¶
The complete app will have all the following URLs:
-
POST
/database/add/
¶ Add a new book via POST
To see in action go to http://building-webapps-with-flask.herokuapp.com/database/add/
Note the use of methods in the decorator to only accept POST.
Parameters: - title – The book’s title
- description – The book’s description
-
GET
/signals/not.json
¶ A simple demo of very specific error handling
To see in action go to http://building-webapps-with-flask.herokuapp.com/signals/not.json?password=sekret
-
GET
/blueprints/
¶ Yet another hello world, but this time inside a blueprint
To see in action go to http://building-webapps-with-flask.herokuapp.com/blueprints/
-
GET
/templates/
(message)¶
-
GET
/templates/
¶ Renders a page using a template
Parameters: - message – Optional message to display
To see in action:
-
GET
/database/
¶ List all the books in JSON
To see in action go to http://building-webapps-with-flask.herokuapp.com/database/
-
GET
/signals/
¶ A simple demo of authentication
To see in action go to http://building-webapps-with-flask.herokuapp.com/signals/?password=sekret
-
GET
/
¶ To see this in action go to http://building-webapps-with-flask.herokuapp.com/
-
GET
/static/
(path: filename)¶ Function used internally to send static files from the static folder to the browser.
New in version 0.5.