![]() To check that open your terminal and run this command python app.py, then go to your browser and see that This is flask blueprint example is printed. from views import index_blueprintĪpp.register_blueprint is the method we used here to register the blueprint with the app object.Īs we have registered our blueprint with the application, it’s time to check if our blueprint is actually working. The following code base shows how to register index_blueprint with app object in app.py file. Now that we have our blueprint object, we need to register it with app object. In the prior example, you can use blueprints to structure your large social media application with different blueprints, such as a users’ blueprint, a blueprint for posts, one for followers, and so on for each feature. And then we have passed _name_ as the second argument which will be used by Flask to locate the Blueprint’s resources. Flask provides a feature called blueprints for making application components. While creating the index_blueprint object, first we have passed the name of the blueprint that will be used in Flask’s routing mechanism. And associates our index function with /index/ url endpoint using route decorator of index_blueprint.Created a Blueprint object and name it index_blueprint.Index_blueprint = Blueprint('index_blueprint', index(): Now create a new file views.py and write the following code in it. While the application is running, go to your favorite browser and see that Hello, World! is printed on it.Īs your basic Flask application is up and running. It will run your application on port 5000 of your machine. Now open up your terminal and write this command python app.py and hit enter. Then we define a function hello_world and associates it with ’/’ url endpoint using route decorator of the app object. What we have done here is that, first we have created an Flask application object by passing the name of the application’s module or package. Create a file app.py and put the following code in it. In this article we will learn how to use Blueprint to structure a Flask project.Īt the beginning, lets first create a hello world application in Flask. To resolve this problem Flask comes with Blueprint.įlask Blueprint or Blueprint for short, is a way to organize the related code base between python modules or packages. But day by day when the application gets bigger and more complex, it become very tough to maintain the code base. It leaves all the design and architecture level decisions to the developer.Īs a result it is very easy to get started start with Flask. ![]() It is designed in such a way that it will only supply the core components of a web application and it lets the developer choose rest of the things. Ap/ Python How to structure a Flask-RESTPlus web service for production builds by Greg Obinna In this guide I’ll show you a step by step approach for structuring a Flask RESTPlus web application for testing, development and production environments. Flask is a lightweight WSGI web application framework based on Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |