在Python Bottle的查询获取中返回默认值

时间:2014-05-19 08:50:00

标签: python bottle

我使用Python Bottle,我想从url中检索一些参数。如果参数中没有值,是否有任何方法可以添加默认值

示例:

myvalue = bottle.request.query.get('value')
if not myvalue:
   myvalue = default_value

而不是这个,我正在寻找类似于Python Dictionaries的东西:

dict.get(key, default=None)

1 个答案:

答案 0 :(得分:0)

瓶子方式实际上更灵活。您需要设置两个路径和参数的默认值才能使其工作:

@bottle.route('/hello')
@bottle.route('/hello/<who>')
def show(who="world"):
    return "Hello, " + who