Blueprints

Even though many basic apps don’t require them I recommend looking into using blueprints to structure your app.

The benefits inclue:

  • Easier to follow code with related views kept together
  • Code re-usability, blueprints are very self contained (e.g.g templates and behaviour such as authentication)

Creating a blueprint involves:

  1. Using flask.Blueprint instead of flask.Flask for your blueprint
  2. Registering it in your app using app.register_blueprint

Code

Blueprints let you compose your application from components

pythonie.blueprints.blueprints.index()[source]

Yet another hello world, but this time inside a blueprint

To see in action go to http://building-webapps-with-flask.herokuapp.com/blueprints/

For reference here’s the application index (and implied link back to the source). You’ll notice some use of configuration in that code too.

pythonie.application.index()[source]

To see this in action go to http://building-webapps-with-flask.herokuapp.com/

URLs

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 /

To see this in action go to http://building-webapps-with-flask.herokuapp.com/