charliegriefer / my-whiskies

MIT License
2 stars 0 forks source link

Handle trailing slash in URL #132

Closed charliegriefer closed 3 months ago

charliegriefer commented 3 months ago

The following URL results in a 404:

http://my-whiskies.online/charlie/bottles/

The issue is Flask expects a route after the trailing slash. But no route should be the same call as:

http://my-whiskies.online/charlie/bottles

charliegriefer commented 3 months ago

Simple fix. Just add both routes in the view.

@main_blueprint.route("/<username>/bottles", methods=["GET", "POST"], endpoint="list_bottles")
@main_blueprint.route("/<username>/bottles/", methods=["GET", "POST"], endpoint="list_bottles")

Another option... use the strict_slashes attribute:

@main_blueprint.route("/<username>/bottles", methods=["GET", "POST"], endpoint="list_bottles", strict_slashes=False)

Conclusion: Implement the strict_slashes solution.