
Use the tree command to create a similar output. The directory structure for the Blueprint should look as shown below. We create a separate directory for our Blueprint with templates and static directories to render Flask views and serve static resources, respectively.

We want our hello2 Blueprint to have its views that we will import in its _init_.py. Touch "$blueprint_name/templates/$blueprint_name/hello.html" Mkdir -p "$blueprint_name/templates/$blueprint_name" Use the below-given script to create the directory structure after activating your virtual environment by using the source venv/bin/activate after going to the application directory. Let’s start creating a Flask Blueprint with the name of hello2. Create Flask Blueprint Files And Directories However, that is likely to create confusion and is not a good practice. You can create multiple Blueprints from the same set of resources.

It means that a Flask Blueprint can have its views, forms, models, static files, and templates. Let’s create a HelloWorld blueprint.Īll components, resources, and features of a blueprint are kept and organized separately from the other source code of the Flask application. We can think of Blueprint as a module too. With the above background given on Flask Blueprint, we can move ahead and design our first Blueprint. A set of operations are recorded and can be subsequently replayed after registering a blueprint.Increases the reusability of code by registering the same Blueprint multiple times.Easy organization of large scale applications.

Some of the benefits of Flask Blueprints are as follows: from flask import Flaskįlask Blueprint lets us keep related features together and helps in better development practices. The instance of the class Flask is the Flask Application, which is the instance of WSGI application. If you notice the code written in the _init_.py file then you will notice that an instance of Flask is created, and the variable is named as app.

