Flask: Blueprints with url_prefix responding in HTTP 308

Created on 24 Jun 2019  路  10Comments  路  Source: pallets/flask

Expected Behavior

2xx response for an existing working URL

Actual Behavior

blueprints with url_prefix started to respond with 308 in the latest flask (used pip)

Environment

  • Python version: Python 3.6.7
  • Flask version: 1.0.3
  • Werkzeug version: 0.15.4

Most helpful comment

same here.
@khera-shanu
try setting strict_slashes to False

app.url_map.strict_slashes = False

All 10 comments

Please provide a minimal piece of example code demonstrating this issue.

read the issue, code won't be required.
I am getting this after latest version flask install, the whole application works on previous versions

Yes, code is required, because you seem to be the only one with this issue. Also, you didn't mention from which version you updated...

Again, please provide a MINIMAL example demonstrating your issue. That means, a single file/snippet one can run with flask run.

same here.
@khera-shanu
try setting strict_slashes to False

app.url_map.strict_slashes = False

@khera-shanu I ran into this problem when refactoring all of my app's routes into separate Blueprint objects. There seems to be a difference in the defaults of Flask.route and Blueprint.route. The former worked as (I) expected with respect to trailing slashes in the url.

For example

app = Flask(__name__)

@app.route('/user')
def user():
    . . .

would work the same whether the request was to /user or /user/.

However, in order to make a Blueprint behave this way, I had to add strict_slashes=False to each of the Blueprint.route calls.

For example

bp = Blueprint('user', __name__, url_prefix='/user')

@bp.route('/', strict_slashes=False)
def user():
    . . .

same issue found, and app.url_map.strict_slashes = False not worked for us.

We found if blueprint.route registered route for sub modules, like /api/module1/ for app/module/entrance.py and defined route like route = ['/', ''] in entrance.py,
when request accepted, it will return a 308 response and then a 200 response, some clients like web browser will handle this, some others will not(such like another web service).

We fixed this by redefine route for this situation:route = '/callbak', and now it's working for good.

For anyone coming from google, I got this error when one of my routes had a trailing slash eg.

@app.route("/foo/")

instead of

@app.route("/foo")

Again, for googlers:

This is because of the strict_slahes setting (default True, see https://werkzeug.palletsprojects.com/en/1.0.x/routing/#maps-rules-and-adapters) and this change in Werkzeug:

https://github.com/pallets/werkzeug/pull/1342

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rkomorn picture rkomorn  路  3Comments

lnielsen picture lnielsen  路  3Comments

chuanconggao picture chuanconggao  路  4Comments

westonplatter picture westonplatter  路  3Comments

dreampuf picture dreampuf  路  3Comments