Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registered blueprint name does not match route blueprint name #177

Open
jdimmerman opened this issue Apr 20, 2022 · 0 comments
Open

Registered blueprint name does not match route blueprint name #177

jdimmerman opened this issue Apr 20, 2022 · 0 comments

Comments

@jdimmerman
Copy link

jdimmerman commented Apr 20, 2022

The blueprint name registered for the app doesn't match that registered for the route.

The app is registered with blueprint name debubtoolbar

module = Blueprint('debugtoolbar', __name__)

But the route is registered with blueprint name _debug_toolbar as implied by the endpoint name _debug_toolbar.static. Thus, in a consuming app, flask.request.blueprint returns _debug_toolbar, which does not exist in flask.current_app.blueprints.

app.add_url_rule('/_debug_toolbar/static/<path:filename>',
                         '_debug_toolbar.static', self.send_static_file)

Three potential fixes - both simple, but may break existing consumers

  • Change the registered BP name to _debug_toolbar
  • Change the endpoint to use the BP name debugtoolbar, and then change the two references of url_for

Ideally in both cases, you'd register the route under the context of the BP to avoid the issue going forward. For example, if you use the second solution

module.add_url_rule('/_debug_toolbar/static/<path:filename>', endpoint="static", view_func=self.send_static_file)

References in url_for, for context:

toolbar.py

self.template_context = {
  'static_path': url_for('debugtoolbar.static', filename='')
}

panels/template.py

'static_path': url_for('debugtoolbar.static', filename=''),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant