Search code examples
pythonrestflaskrouteswerkzeug

Flask route query parameter


Say I have two routes set up with Flask:

app.add_url_rule('/example', view_func = example.Index.as_view('example'))
app.add_url_rule('/example/<string:example_key>', view_func = example.Show.as_view('example'), methods=['GET'])

This routes /example to example.Index and /example/1 to example.Show.

When I go to /example?parameter=miau however it routes to example.Show instead of example.Index.

Why does this happen and how should I solve this?


Solution

  • Found out, mind the "example.Index.as_view('example')", it should be:

    app.add_url_rule('/example', view_func = example.Index.as_view('example_index'))
    app.add_url_rule('/example/<string:example_key>', view_func = example.Show.as_view('example_show'), methods=['GET'])