Bootstrap FreeKB - Flask - Resolve 308 Redirect
Flask - Resolve 308 Redirect

Updated:   |  Flask articles

Let's say your Flask app has the following route.

@app.route("/api/v1")
def apiv1():
  return "hello world"

 

And when requesting /api/v1 (without the trailing slash) a 308 Redirect is being returned. On the other hand, requesting /api/v1/ (with the trailing slash) returns "hello world" in the route.

This happens because Flask uses werkzeug.routing.Rule which sets strict_slashes to True. With this configuration, the trailing slash must be included. If you want to allow requests without the trailing slash, set strict_slashes to False.

@app.route("/api/v1", strict_slashes=False)
def apiv1():
  return "hello world"

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 2ae755 in the box below so that we can be sure you are a human.