Flask可以通过在请求的URL中添加<>以识别参数
@app.route("/book/search/<q>/<page>")
def search(q,page):
pass
但是这种方式不够优雅,如果想要请求信息为"/book/search?q=xxx&page=1"这样的URL的话也没有办法取得其中的值。所以需要使用Flask中的request对象。
为了获取以问号开头的数据的信息,可以使用request.args['q']。官方文档的描述为:
property args
The parsed URL parameters (the part in the URL after the question mark).
解析的URL参数(URL中问号后的部分)
By default an ImmutableMultiDict
is returned from this function. This can be changed by setting