Skip to content
Advertisement

Allow for multiple optional arguments in a Flask URL

So I have a flask URL, where there are 2 separate arguments. I want to run the same function with either no arguments, just the first or both. If no specific value is set, I want the unaccounted for arguments to get value None (as opposed to just not existing at all). My current solution involves using 3 @app.route statements, and I was wondering if there was something more efficient i’ve missed.

JavaScript

Thanks!

Advertisement

Answer

In that case, just create simple route and access those variables in request.args like so:

JavaScript

And then in url you can pass like this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement