Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Repetition in code for routes in Flask (or Bottle)

I have at least 10 routes like this:

@app.route("/foo/bar")
def foo_bar():
    return render_template('foo_bar.html')

@app.route("/foo/baz")
def foo_baz():
    return render_template('foo_baz.html')

...

Each name is repeated three times: the name of the route, the name of the Python function, the name of the template.

What is the standard way with Flask (or Bottle) to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Something like that?

@app.route("/foo/<arg>")
def foo_arg(arg):
    return render_template(f"foo_{arg}.html")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading