Some of the recent PRs in blueprint.py seem to make Flask 1.0 not backwards compatible with 0.x versions. When url_prefix='', url_prefix='/', or url_prefix is not specified, a ValueError('urls must start with a leading slash') is now raised.
Expected Behavior
I would have assumed, given the discussion in #2629, that '' and maybe / would be acceptable url_prefixes to indicate the blueprint is meant for the root.
An example of a broken library is flask-sitemap (https://github.com/inveniosoftware/flask-sitemap/blob/master/flask_sitemap/__init__.py#L120) which uses
app.register_blueprint(
self.blueprint,
url_prefix=app.config.get('SITEMAP_BLUEPRINT_URL_PREFIX') # default is '/'
)
Actual Behavior
In my testing, I continually get
self.init_app(app)
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask_sitemap/__init__.py", line 120, in init_app
url_prefix='' # app.config.get('SITEMAP_BLUEPRINT_URL_PREFIX')
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask/app.py", line 64, in wrapper_func
return f(self, *args, **kwargs)
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask/app.py", line 1113, in register_blueprint
blueprint.register(self, options, first_registration)
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask/blueprints.py", line 186, in register
deferred(state)
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask/blueprints.py", line 207, in <lambda>
s.add_url_rule(rule, endpoint, view_func, **options))
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask/blueprints.py", line 79, in add_url_rule
view_func, defaults=defaults, **options)
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask/app.py", line 64, in wrapper_func
return f(self, *args, **kwargs)
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/flask/app.py", line 1211, in add_url_rule
rule = self.url_rule_class(rule, methods=methods, **options)
File "/home/albertyw/.virtualenvs/baseflask/local/lib/python2.7/site-packages/werkzeug/routing.py", line 603, in __init__
raise ValueError('urls must start with a leading slash')
ValueError: urls must start with a leading slash
unless I set url_prefix='//', in which case the url_prefix is the root.
Environment
- Python version: python 2.7 and 3.6
- Flask version: 1.0
- Werkzeug version: 0.14.1
Some of the recent PRs in blueprint.py seem to make Flask 1.0 not backwards compatible with 0.x versions. When
url_prefix='',url_prefix='/', orurl_prefixis not specified, aValueError('urls must start with a leading slash')is now raised.Expected Behavior
I would have assumed, given the discussion in #2629, that
''and maybe/would be acceptable url_prefixes to indicate the blueprint is meant for the root.An example of a broken library is
flask-sitemap(https://github.com/inveniosoftware/flask-sitemap/blob/master/flask_sitemap/__init__.py#L120) which usesActual Behavior
In my testing, I continually get
unless I set
url_prefix='//', in which case the url_prefix is the root.Environment