Python 如何在Flask棉花糖模式中加载查询字符串参数

Python 如何在Flask棉花糖模式中加载查询字符串参数,python,flask,marshmallow,Python,Flask,Marshmallow,我在我的Flask应用程序中定义了一个POST请求,如下所示: https://www.foo.com/<foo_id>?bar_id=3 from flask_restplus import Namespace, Resource ns = Namespace('Foo API') @ns.route("/<string:foo_id>") class FooExecute(Resource): def get(self, foo_id):

我在我的Flask应用程序中定义了一个POST请求,如下所示:

https://www.foo.com/<foo_id>?bar_id=3
from flask_restplus import Namespace, Resource

ns = Namespace('Foo API')

@ns.route("/<string:foo_id>")
class FooExecute(Resource):

    def get(self, foo_id):
        print('foo_id = {}'.format(foo_id))
虽然我无法获取查询参数
条形码id
。检索它的正确方法是什么?

您可以尝试使用Flask中的类获取参数,如下所示:

来自flask导入请求
request.args.get('bar\u id')

Am使用请求方法,这是最好的

见文件

首先,您需要通过安装和导入请求

pip install requests
下面是一个适用于您的示例代码。 只需用主值替换

import requests
import json

item = { "bar_id: "3"}
resp1 = requests.post("https://www.foo.com.com/<foo_id>/?", 
              data=(item)
             )

print('data sent successfully')
print (resp1.status_code)


content = json.loads(resp1.content)
print(content)
导入请求
导入json
item={“bar_id:“3”}
resp1=requests.post(“https://www.foo.com.com//?", 
数据=(项目)
)
打印('数据已成功发送')
打印(响应1.状态代码)
content=json.load(resp1.content)
打印(内容)