【问题标题】:Multiple arguments in bottle's route瓶子路线中的多个参数
【发布时间】:2013-05-23 11:46:56
【问题描述】:

在瓶子里,路线是这样的:

@get('/ws/contacts/:uid')

如何向路由添加更多参数,以及如何编写 @get() 代码?

【问题讨论】:

标签: python-2.7 bottle


【解决方案1】:

只需使用多个通配符:

@get('/ws/contacts/:uid/:itemid')
def get_user_item(uid, itemid):
    return 'you passed in uid={} and itemid={}'.format(uid, itemid)

P.S.,您使用的是已弃用的通配符语法。除非您需要使用旧版本的 Bottle(0.9 或更早版本),否则我建议您使用 modern syntax,如下所示:

@get('/ws/contacts/<uid:int>/<itemid:int>')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-08
    • 2021-10-08
    • 2020-02-07
    • 1970-01-01
    • 2020-11-16
    • 2017-09-30
    • 2013-06-21
    • 1970-01-01
    相关资源
    最近更新 更多