I have HTML form input field that returns a list of dictionaries I want to get values from using PYthon in Django View.
(我有HTML表单输入字段,该字段返回字典列表,我希望从Django View中使用PYthon获取值。)
The form returns:
(表单返回:)
request.POST['tags'] returns => [{"value":"summer"},{"value":"winter"}]
When I try interating through it using [tag['value'] for tag in request.POST['tags']]
to get values, I get TypeError: string indices must be integers
.
(当我尝试使用[tag['value'] for tag in request.POST['tags']]
遍历以获取值时,出现TypeError: string indices must be integers
。)
However, if I manually copy the input field results to command line and go line by line it works as expected:
(但是,如果我手动将输入字段的结果复制到命令行并逐行进行,它将按预期工作:)
>>> test = [{"value":"summer"},{"value":"winter"}]
>>> test
>>> [{'value':'summer'},{'value':'winter'}]
>>> [tag['value'] for tag in test]
>>> ['summer', 'winter']
What is happening?
(怎么了?)
ask by curtisp translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…