Flask可选URL参数不起作用。

3
@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 .. */

我可以访问 http://localhost:5000/participate/512dc365fe8974149091be1f 或者 http://localhost:5000/participate/512dc365fe8974149091be1f/。如果我启动调试器,我会看到work_id = None
如果我尝试访问 http://localhost:5000/participate/512dc365fe8974149091be1f/512dc365fe8974149091be1f 或者 http://localhost:5000/participate/512dc365fe8974149091be1f/512dc365fe8974149091be1f/,我会得到404错误。
为什么会这样?我的路由规则有问题吗?
1个回答

2
你的第二个路由有一个拼写错误 :)
@mod.route('/pariicipate/<survey_id>/<work_id>', methods = ['GET', 'POST'])

应该是

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

1
最好的人也会遇到这种情况 :) PS:您应该将答案标记为已接受。 - entropy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接