A Love Story
Blueprints are the recommended way to implement larger or more pluggable applications in Flask 0.7 and later.
A Blueprint object works similarly to a Flask application object, but it is not actually an application. Rather it is a blueprint of how to construct or extend an application.
Blueprints are "subapplications" that encapsulate related logic and the only way to sanely grow an application.
Flask Application ≅ Django Project
Blueprint ≅ Django Application
A single file containing most of your application code
A few files representing your MVC structure
Change this:
from ..core import app ... @app.route('/users/') def user_list(): ...
To this:
from flask import Blueprint bp = Blueprint('users', __name__, template_folder='templates') ... @bp.route('/') def user_list(): ...
And add this:
from .users.views import bp as user_bp ... app.register_blueprint(user_bp, url_prefix='/users')
(Questions?)
Space | Forward |
---|---|
Left, Down, Page Down | Next slide |
Right, Up, Page Up | Previous slide |
P | Open presenter console |
H | Toggle this help |