Replies: 1 comment
|
This comes from Werkzeug routing not Flask and the redirect for
Werkzeug
https://github.com/pallets/werkzeug/blob/main/CHANGES.rst The fix is a single rule with @blueprint_api.route('/project/<path:category>/', methods=['POST'], strict_slashes=False)
def project_category(category):
...Verified on Flask Swapping your decorator order also avoids the redirect but then |
Uh oh!
There was an error while loading. Please reload this page.
Context
Not sure if this is a bug or intentional feature. When using Blueprint route with Flask, I understand routes with trailing
/can be used to handle routes with and without/. (e.g./api/do/stuffand/api/do/stuff/.When you have route:
When user enters a route
/project/food/, it will return whatproject_categorydoes and returns, but when user enters/project/food, it will redirect to/project/food/.So if you don't want the redirect, you might do something like:
Replicate
Now this works fine if the dynamic route uses
stringtype, but it seem to be working differently forpathtype.With the
pathtype, even when you specify both routes, the route without the trailing/will still redirect to route with trailing/even though it is specified as a route.Expect
I was expecting the same behavior for both
stringtype dynamic route parameter andpathtype dynamic route parameter?Environment: macOS 14.3 (23D56)
All reactions