在 Python 中获取数组作为 GET 查询参数

编程入门 行业动态 更新时间:2024-10-27 08:25:52
本文介绍了在 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 查询参数

本文发布于:2023-10-29 13:22:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   参数   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!