Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask Blueprint Index URL keeps adding trailing slash

The blueprint is defined as

publicweb_bp = flask.Blueprint('publicweb', __name__, url_prefix='/<lang_code>/<country_code>/<market_code>')

I have an index route defined as

@publicweb_bp.route('/', strict_slashes = False)
def pp_index():
    return 'Hello'

and another route defined as

@publicweb_bp.route('/abc', strict_slashes = False)
def pp_index():
    return 'Abcdefg :P'

The problem is that when I access the url for e.g.

http://localhost/en/us/m1

it always sends me to

http://localhost/en/us/m1/

But if I access

http://localhost/en/us/m1/abc

it keeps me on

http://localhost/en/us/m1/abc

I have even tried playing with the strict_slashes option and turned it OFF , but has no effect.

It doesn't seem to work, even thought it works for all other URLs of the blueprint for e.g. '/abc'

Another thing I noticed was that if I don't use a blueprint and define a '/' route on the app itself with strict_slashes = False, it works as expected !

like image 763
Storm Avatar asked Oct 30 '22 09:10

Storm


1 Answers

Try

@publicweb_bp.route('', strict_slashes=False)

This works for me in Flask v1.1.1

like image 60
booshong Avatar answered Nov 15 '22 07:11

booshong