无法使用 Bottle Web 框架捕获整个 URL 字符串

Unable to capture the whole URL string with Bottle web framework

我有一个小 Bottle hello world 类型代码:

from bottle import route, run, template

@route('/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

现在,当我在浏览器中键入以下字符串时 (chrome):

http://localhost:8080/navigator?search_term=arrow/

它出现了消息: 导航员您好!

我的 objective 是在名称参数中捕获术语箭头,以便我可以使用它来使用索引函数显示其他内容。

请帮助我如何在我提供的 URL 中捕获术语箭头。

提前感谢您的任何建议。

您混淆了 url 的 path 和它的 query args。以下是获取查询参数的方法:

from bottle import route, run, template, request

@route('/navigator')
def index():
    name = request.params['search_term']
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

这会产生您想要的结果:

% curl 'http://localhost:8080/navigator?search_term=arrow/'
<b>Hello arrow/</b>!

文档是 here。祝你好运!