Creating a blueprint - Aimlackies/Reporter GitHub Wiki
This is a basic guide on creating a new blueprint
-
Add blueprint import to
__init__.pyAdd the collowing to the function called
create_app()inreporter_app/__init__.py. Replaceblueprint_namewith a descriptive (but short) name for the blueprint.from reporter_app.blueprint_name import bp as blueprint_name_bp app.register_blueprint(blueprint_name_bp) -
Create 2 folders with the name of the blueprint. The first will go at
reporter_app/blueprint_nameand the secondreporter_app/templates/blueprint_name. -
Create the basic blueprint files in
reporter_app/blueprint_namei. Create a file called__init__.pyand past this code (changingblueprint_nameto the name of the blueprint)from flask import Blueprint bp = Blueprint('blueprint_name', __name__) from reporter_app.blueprint_name import routes from reporter_app.blueprint_name import formsii. Create two additional files in
reporter_app/blueprint_name. The first will be calledroutes.pyand the secondforms.py -
You are done! Well... kind of. Now its up to you to add the rest, but that will depend on what you are adding so the steps for doing so are down to you. From steps 1 to 3 you will have a file structure with a few new folders and files which will kind of look like this:
Repository root
|
|-reporter_app
| |
| |-blueprint folder
| | |
| | |-__init__.py
| | |-routes.py
| | |-forms.py
| |
| |-templates
| | |
| | |-blueprint folders
| |
| |-__init__.py