瓶可选的url参数不起作用 [英] flask optional url parameter not working

查看:157
本文介绍了瓶可选的url参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @ 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/512dc365fe8974149091be1for 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参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆