Note that there are some explanatory texts on larger screens.

plurals
  1. POurl_for Builderror in flask extension with pluggable views
    primarykey
    data
    text
    <p>I am building a simple extension for flask and have a problem with the url_for function not being able to build the urls within the extension.</p> <p>Can somebody help me figure out what I am missing here?</p> <p>I simplified the code to demonstrate the issue (all of the url_for calls raise a werkzeug BuildError exception):</p> <pre class="lang-py prettyprint-override"><code>import flask import flask.views import logging logging.basicConfig(level=logging.DEBUG) class MyFlaskExt(object): def __init__(self, app=None): if app is not None: self.init_app(app) def init_app(self, app): self.blueprint = flask.Blueprint('myext', __name__, static_folder='static', template_folder='templates') self.blueprint.add_url_rule('/', view_func=RootView.as_view('root'), endpoint='root') self.blueprint.add_url_rule('/var/&lt;somevar&gt;', view_func=VarView.as_view('var'), endpoint='var') self.blueprint.add_url_rule('/novar', view_func=NoVarView.as_view('novar'), endpoint='novar') app.register_blueprint(self.blueprint) class RootView(flask.views.View): def dispatch_request(self): logging.debug(flask.url_for('novar')) logging.debug(flask.url_for('novar', _external=True)) return flask.redirect(flask.url_for('var', somevar='test')) class VarView(flask.views.View): def dispatch_request(self, somevar): return "SUCCESS! ({})".format(somevar) class NoVarView(flask.views.View): def dispatch_request(self): return "SUCCESS!" if __name__ == '__main__': app = flask.Flask(__name__) app.debug = True my_ext = MyFlaskExt() my_ext.init_app(app) logging.debug(app.url_map) app.run() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload