在 Python 中获取数组作为 GET 查询参数 [英] Getting the array as GET query parameters in Python

查看:32
本文介绍了在 Python 中获取数组作为 GET 查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 php 中,我可以只使用 $_GET['key1']['key2'] 来检索以数组形式发送的 GET 数据,但在 Python 中可以这样做吗因为我刚收到一个字符串,它不被识别为数组/列表.

I know in php I could just use $_GET['key1']['key2'] to retrieve GET data that is sent in the form of an array but is that something possible in Python as I just receive a string and it's not recognized as an array/list.

如果重要的话,我会使用flask/werkzeug.

I use flask/werkzeug if that matters.

推荐答案

参数名称的深度解析是 PHP AFAIK 独有的.

The deep parsing of argument names is unique for PHP AFAIK.

如果您只需要一个简单的列表,只需传递几个具有相同名称的参数并使用 request.args.getlist(<paramname>) (文档).

If you need just a simple list, just pass several parameters with the same name and use request.args.getlist(<paramname>) (documentation).

否则你必须自己解析查询字符串.

Otherwise you have to parse the query string yourself.

这篇关于在 Python 中获取数组作为 GET 查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆