且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用python,flask和命令行传递URL参数

更新时间:2023-02-23 22:47:03

您应该将查询参数排除在路由之外,因为它们不属于该路由。

You should leave the query parameters out of the route as they aren't part of it.

@app.route('/post', methods=['GET'])
def show_post():
    post_id = request.args.get('id')
    return post_id

request.args 是一个包含URL中传递的所有查询参数的字典。

request.args is a dictionary containing all of the query parameters passed in the URL.