python - Flask request.args.get 没有获取所有参数(Python)

标签 python flask get python-requests

这类似于此处提出的问题和示例:Flask request.args.get get all params (Python)

不确定我是否错误地使用了 request.args.get(),但我只能获得传递的第一个参数。例如,对于我的 flask 应用程序:

@app.route('/longword/')
def longword():

    gid = request.args.get('gameid')
    pid = request.args.get('playerid')
    print("param1: ", gid, "\n")
    print("param2: ", pid, "\n")
    print("request args", request.args)

    return "GID: %s  PID: %s" % (gid, pid)

app.run()

我的查询:curl http://localhost:5000/longword/?gameid=123&playerid=456,我总是得到第一个参数,但第二个参数总是没有返回。

param1:  123 

param2:  None 

request args ImmutableMultiDict([('gameid', '123')])

最佳答案

使用 curl 时,将您的 url 放在双引号中

curl "http://localhost:5000/longword/?gameid=123&playerid=456"

归功于 Bidhan here

关于python - Flask request.args.get 没有获取所有参数(Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62205493/

相关文章:

python - 如何将 Django 应用程序测试与其他测试一起运行?

Python:线程无故停止

python - 将不同的样式表应用于模板的不同元素

javascript - 通过 GET 传递带有新行的文本字符串破坏了我的重定向

android - 在 AsyncTask 中同时使用 POST 和 GET http 请求

java - 如何在列表字段上使用 field.get(obj)?

python - OpenCV Python 3.3

amazon-web-services - 如何将基本身份验证添加到托管在 Amazon Elastic Beanstalk 上的 Python REST API?

python - 我的 .fetchall() 没有在我的 Flask 应用程序上更新?

python - 将 PyTorch 模型 state_dict 保存到 redis 缓存中