Vinyll's blog

( Python, Javascript & Web stuff… )

Getting started with Flask

Routing

Making parameters optional

@app.route("/")
@app.route("/<slug>")
def index(slug=None):
    return render_template('index.html')

This will call index() when url matches "/" or "/anything/here"

Making a catchall route

@app.route("/<path:slug>")
def catchall(slug=None):
    return render_template('catchall.html')

This will call index() when url matches anything else than "/"

By vinyll on Aug. 22, 2012


Comments