python - What are Flask Blueprints, exactly? -


i have read the official flask documentation on blueprints , one or two blog posts on using them.

i've used them in web app, don't understand or how fit app whole. how similar instance of app not quite? documentation comprehensive seek layman explanation or enlightening analogy spark me. sufficiently perplexed when colleague asked me explain flask blueprint them elected ask here.

a blueprint template generating "section" of web application. think of mold:

a medallion mold gold medallion freshly removed it

you can take blueprint , apply application in several places. each time apply blueprint create new version of structure in plaster of application.

# example flask import blueprint  tree_mold = blueprint("mold", __name__)  @tree_mold.route("/leaves") def leaves():     return "this tree has leaves"  @tree_mold.route("/roots") def roots():     return "and roots well"  @tree_mold.route("/rings") @tree_mold.route("/rings/<int:year>") def rings(year=none):     return "looking @ rings {year}".format(year=year) 

this simple mold working trees - says application deals trees should provide access leaves, roots, , rings (by year). itself, hollow shell - cannot route, cannot respond, until impressed upon application:

from tree_workshop import tree_mold  app.register_blueprint(tree_mold, url_prefix="/oak") app.register_blueprint(tree_mold, url_prefix="/fir") app.register_blueprint(tree_mold, url_prefix="/ash") 

once created may "impressed" on application using register_blueprint function - "impresses" mold of blueprint on application @ locations specified url_prefix.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -