DEV Community

loading...
Cover image for Flask Blueprints | Simple, Scalable

Flask Blueprints | Simple, Scalable

Henshal B
Python developer with a special affection to Flask. JavaScript with Python makes the real combo. I do that.
・1 min read

Flask blueprints makes development of a web app super simple. Yes, an easy web app using most powerful programming language Python. Don't go to the confusing Django framework. Flask does it efficiently. I'll explain that in a few simple steps.

  1. You should have a main app directory where you must include blueprints. That's how it's done usually.
  2. The main python file should appear there almost barely. Inside this we add the Flask instance, main method and blueprint registration.
  3. So decide what should be the first blueprint. Profile? Make a folder named Profile.
  4. Open Profile folder and make it a module. How? Create a Python file named init.py.
  5. Keep the file blank.Some tutorials teach you to fill init.py. Don't do that. It will make the web app slower.
  6. Add your Profile related functions and classes right inside the created Python file in that folder.
  7. To that Python file, which you created earlier, import Blueprints from Flask.
  8. Add these lines. profile_blueprint=Blueprint('profile', name)
  9. Go to main file which is in the main app folder. Register the blueprint using lines below. app.register_blueprint(profile_blueprint).
  10. To use blueprint you must import it. So import it as you do in the case of Python modules. How? from profile import profile_blueprint. The first keyword is the module name and the second is blueprint name.

That's all. Start building your dream today. Do it segmented. Scale gradually. All the best.

Discussion (0)