网站开发的目的意义,广州最新通知,太原网站关键词排名,深圳网页设计学校在Django视图中#xff0c;您可以访问request.GET[variablename]#xff0c;因此在您的视图中#xff0c;您可以执行如下操作#xff1a;myvar request.GET[myvar]
实际的request.GET[myvar]对象类型是#xff1a;
现在#xff0c;如果要传递具有相同参数名的多个变量您可以访问request.GET[variablename]因此在您的视图中您可以执行如下操作myvar request.GET[myvar]
实际的request.GET[myvar]对象类型是
现在如果要传递具有相同参数名的多个变量即
http://example.com/blah/?myvar123myvar567
您希望为参数myvar返回pythonlist然后执行以下操作for var in request.GET[myvar]:
print(var)
但是当您尝试只获取url中传递的最后一个值时即在上面的示例中您将获得567shell中的结果将是5
6
7
然而当你打印request.GET时它似乎有一个list即
确定更新
它的目的是返回最后一个值我的用例是我需要一个列表。
来自django docsQueryDict.getitem(key)
Returns
the value for the given key. If the
key has more than one value,
getitem() returns the last value. Raises
django.utils.datastructures.MultiValueDictKeyError
if the key does not exist. (This is a
subclass of Pythons standard
KeyError, so you can stick to catching
KeyError
QueryDict.getlist(key) Returns the
data with the requested key, as a
Python list. Returns an empty list if
the key doesnt exist. Its guaranteed
to return a list of some sort.
更新
如果有人知道django dev为什么这么做请告诉我显示一个列表似乎是违反直觉的而且它的行为不像一个列表。不是很Python