Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask optional url parameter not working [closed]

Tags:

python

url

flask

@mod.route('/participate/<survey_id>/', defaults = {'work_id':None}, methods = ['GET','POST'])
@mod.route('/pariicipate/<survey_id>/<work_id>', methods = ['GET', 'POST'])
def participate(survey_id, work_id):
   /* do_something .. */

I can access http://localhost:5000/participate/512dc365fe8974149091be1f or http://localhost:5000/participate/512dc365fe8974149091be1f/ and if I fire up a debugger I can see that work_id = None.

If I try http://localhost:5000/participate/512dc365fe8974149091be1f/512dc365fe8974149091be1for http://localhost:5000/participate/512dc365fe8974149091be1f/512dc365fe8974149091be1f/ I get 404.

why is this happening? Is there something I've done wrong with routing rules?

like image 347
thkang Avatar asked Jan 27 '26 10:01

thkang


1 Answers

Your second route has a typo in it :)

@mod.route('/pariicipate/<survey_id>/<work_id>', methods = ['GET', 'POST'])

should be

@mod.route('/participate/<survey_id>/<work_id>', methods = ['GET', 'POST'])
like image 112
entropy Avatar answered Jan 29 '26 23:01

entropy