Last active
March 10, 2024 18:26
-
-
Save Jaza/61f879f577bc9d06029e to your computer and use it in GitHub Desktop.
Example of how to split a Flask blueprint into multiple files, with routes in each file, and of how to register all those routes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| app = Flask(__name__) | |
| app.debug = True | |
| @app.route('/') | |
| def home(): | |
| return 'App home' | |
| from foo import mod | |
| app.register_blueprint(mod, url_prefix='/foo') | |
| if __name__ == '__main__': | |
| app.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| * |
cool
why don't you simply use Nesting Blueprints ? https://flask.palletsprojects.com/en/3.0.x/blueprints/#nesting-blueprints ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpfull example. I exemined your way of solving problem and came up to this solution:
So you can do smth like this: