烧瓶URL路线:将几个URL路由到同一功能
我正在使用烧瓶0.9。
现在,我想将三个URL路由到相同的函数:
/item/<int:appitemid>
/item/<int:appitemid>/
/item/<int:appitemid>/<anything can be here>
&lt;任何东西都可以在这里&gt;
零件永远不会在该功能中使用。
我必须两次复制相同的功能才能实现此目标:
@app.route('/item/<int:appitemid>/')
def show_item(appitemid):
@app.route('/item/<int:appitemid>/<path:anythingcanbehere>')
def show_item(appitemid, anythingcanbehere):
会有更好的解决方案吗?
I am working with Flask 0.9.
Now I want to route three urls to the same function:
/item/<int:appitemid>
/item/<int:appitemid>/
/item/<int:appitemid>/<anything can be here>
The <anything can be here>
part will never be used in the function.
I have to copy the same function twice to achieve this goal:
@app.route('/item/<int:appitemid>/')
def show_item(appitemid):
@app.route('/item/<int:appitemid>/<path:anythingcanbehere>')
def show_item(appitemid, anythingcanbehere):
Will there be a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用可能为空的参数,默认值
none
?Why not just use a parameter that can potentially be empty, with a default value of
None
?是的 - 您使用以下结构:
Yes - you use the following construct: