您混淆了使用捕获的url参数和
<variable>使用访问的查询参数
request.args。从路由定义中删除查询参数,然后在视图中访问它。
from flask import request@app.route('/')def index(): return render_template('index.html')@app.route('/search')def search(): search = request.args.get('search') # will be None if form wasn't submitted # do something with search return render_template('search.html', search=search)index.html:
<form action="{{ url_for('search') }}"> <input name="search"/> <input type="submit" value="Search"/></form>


