flask optional url parameter not working [closed]

2019-07-12 18:33发布

@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?

标签: python url flask
1条回答
乱世女痞
2楼-- · 2019-07-12 19:01

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'])
查看更多
登录 后发表回答