问题描述
@ mod.route('/ participation /< survey_id> /',defaults = {'work_id':None},methods = ['GET','POST'])
@ mod.route('/ pariicipate /< survey_id> /< work_id>'方法= ['GET','POST'])
def参与(survey_id,work_id):
/ * do_something .. * /
我可以访问 http:/ / localhost:5000 / participa / 512dc365fe8974149091be1f
或 http:// localhost:5000 / participa / 512dc365fe8974149091be1f /
如果我启动我可以看到 work_id = None
。
如果我尝试 http:/ / localhost:5000 / participa / 512dc365fe8974149091be1f / 512dc365fe8974149091be1f
或 http:// localhost:5000 / participa / 512dc365fe8974149091be1f / 512dc365fe8974149091be1f /
/ p>
为什么会发生这种情况?有没有什么我做了错误的路由规则?
你的第二条路线有一个错字:)
@ mod.route('/ pariicipate /< survey_id> /< work_id>,methods = ['GET','POST '])
应该是
<$ p $ >
@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/512dc365fe8974149091be1f
or http://localhost:5000/participate/512dc365fe8974149091be1f/512dc365fe8974149091be1f/
I get 404.
why is this happening? Is there something I've done wrong with routing rules?
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'])
这篇关于瓶可选的url参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!