Trailing Slashes and Redirect Behavior
Understand canonical URLs and automatic redirects.
One Slash Changes Everything
To Flask, /about and /about/ can be two different things. That tiny trailing slash decides how a route matches and whether a redirect happens.
Route Defined With a Slash
When your route ends in a slash, it behaves like a folder. Visiting /docs/ works, and /docs gets redirected to the slashed version. 📁
@app.route('/docs/')
def docs():
return 'Docs'All lessons in this course
- Capture Variables from the Path
- Type Converters: int, float, string, path
- Build URLs with url_for
- Trailing Slashes and Redirect Behavior