Simplifying with Blueprints
This content is not available in your language yet.
Following PEP 20 which states that “Simple is better than complex”, we will be simplifying our code by using blueprints. Blueprints are a way to organize a group of related views and other code. They are registered with the application and can be used to create a modular application.
- app.py
This gets turned into a tree structure like this:
- app.py
- blog.py
- …
Creating a Blueprint
To create a blueprint, we need to create a new file called blog.py
. We will then create a blueprint object and define the routes for the blog.
We then need to register the blueprint with the application in app.py
.
- Visit http://127.0.0.1:5000/ to see
Blog Index
- Visit http://127.0.0.1:5000/post/1 to see
Post 1