Exercises, examples and other material relating to training module Y307. This module is presented on Private Courses
and Specially Run Courses
Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. Running as a server, requests are routed via Werkzeug and pages generated (templated) through Jinja, providing a toolset to allow Python applications to be run on a web server / accessed via a browser without tedious coding, and leading to a fast development cycle.
|Articles and tips on this subject||updated|
|4540||Unittest of a Flask application including forms|
Moving on from the single file "Hello Flask Test World" at [here], I've now uploaded an example that takes a Flask application including a form - it's [here] and based on our earlier form demo and runs it through unit test [here].
It runs with all tests passing:
WomanWithCat:flask grahamellis$ ...
|4538||Flask and unittest - hello web app test world|
Flask comes with a test client that you can use within unittest - I've put together a really short test of "hello world" [here]. The test example is ugly with the Flask application within the test harness, and should be improved by the importing of the appication to be tested. ...
|4534||Flask - complete MVC site to navigate around a data set|
A full demonstration from today - Flask Model, View and Controller. There's an index page listing links to all UK railway stations, and individual pages (via a 3 letter code URL) for each station. Here's the log of a session:
and some of the pages in that session:
The main router ...
|4533||Sessions in flask|
Sessions are available in flask through the session object which can be treated as a python dict. There's an example which srores anyone filling in the "Hello" page on our signin form [here] and the template associated wit it is [here].
|4532||Flask - first forms and responses with wtforms|
Using Flask, the wtforms module lets you set up your own forms - example [here] with the jinja template [here]. This example sets the for up, but does not handle reponses - indeed, a form submitted back will generate an error 405 and I have used this opportunity to use the app.errorhandler decorator ...
|4531||Jinja2 - Flask templating |
So far, we've only done simple inserts in our template - but there may be a requirement to do more - for example to insert a whole table of values. And this requires programatic elements in our template.
Whilst it would be nice if we could simply include Python code in our template (Like Ruby on Rails ...
|4530||Requests in Flask|
Your request object contains many fields of information - you can access the query string and the headers as well as individual parameters entered into forms using the GET or the POST methods, or both. There are various layers of dispatch of requests (we can come back to these later) - just look at the ...
|4529||Flask - calling in the templating engine|
In previous steps, we have set up flask [here] and done some routing [here]. Let's now define our view.
Our view is in HTML (and with style and lots of other stuff later) and the template will be produced by an HTML expert and graphic artist, and not by a programmer. It will be in a separate place ...
|4528||Routing in Flask|
Having got "hello world" working on your server in Flask (see [here] if you haven't!), you'll want to add further routes for other URLs - and indeed you'll want those routes to contain match markers so you can set up whole families of URLs. Our first example included:
|4527||Hello Flask world / Python web micro framework|
Flask is a microframework for web appliactions - in other words, it provides the structure for you to write web based applications on your server in Python without the need to get involved with detailed coding common to most applications - allyou need to is to take the framework provided and fill in ...
Examples from our training material
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
Basic Flask application structure; virtual environments
Server, routes, views, request / response cycle under Flask
The Jinja2 tempting engine, including nested templates, forms,
Routing and redirects
Databases with SQL
Request, configuration and Responses
Testing, faking, error handling, Unit testing, Code coverage
Callbacks, Pluggable views, Blueprints
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.