Is there a way to make paths optional?
For example:
@app.route(r'/contacts/<key>/<name>?', methods=['GET'])
def contact_deatils(key, name = None):
print(key, name)
return 'mensaje de prueba'
if to place parameters to the routes yes, but also that they be optional for example. I have this in the routes '/contacts/<key>/<name>?'
if I put the url /contacts/1/
, which will let me view the page, but I get an error and it forces me to put the two parameters. And when placing the url /contacts/1/nombre/
, it also shows me the page
It is possible to use multiple routes for the same function so you have something like this:
You may have to validate, within the function, the parameters you have received. In this case
key
it will always be present butname
maybe it isNone
:It's simple.
By the way, I think that the "raw string" for the routes are not necessary:
r'...'