QuickDevGuide

Home › Flask Framework

Routing & URL Building — Flask Framework

Routes map a URL pattern and HTTP method to a view function. Flask 2+ adds method shortcuts: @app.get, @app.post, @app.put, @app.delete, @app.patch. Variable rules (converters) Rule Matches Python type <name> any text without / str <int:id> positive integers int <float:price> floats float <path:subpath> text including / str <uuid:token> UUID strings uuid.UUID URL building Never hard-code links — use urlfor("viewname", params). It respects the app's root path, escapes values and adds unknown params as a query string. Inside a request it is also how templates build links: {{ urlfor('static', filename='app.css') }}. Trailing slashes /projects/ redirects /projects to the slash form; /about (no slash) returns 404 for /about/. Pick one style and stay consistent.

Key Takeaways