python - Flask: Getting at Blueprint options in view code -
flask's blueprints let me pass optional values when register blueprint. how them later?
from flask import blueprint, g bp = blueprint('test', __name__, url_prefix='/test') @bp.route('/') def index(): ... value of `foo` from? ... app.register_blueprint(bp, foo="bar")
as far can see options pass in register_blueprint
used flask's internal setup of blueprint (e.g. configuring url_prefix, subdomain, etc. options). aren't available @ request time.
maybe helpful if explain why want access value within request?
have considered using pluggable view?
http://flask.pocoo.org/docs/views/
with views can subclass view
, override __init__
pass values in usable within request.
you can subclass blueprint , same thing, it's little more code & complexity. did here (see blueprintwrapper). although if rewrite try rid of metaclass.
Comments
Post a Comment