我的Python unicode字典如下所示:
`<QueryDict: {u'csrfmiddlewaretoken':[u'oacUfIz5q2tPtmSoqCQi7tBDn2ejpt4x9ZiFeLKeIOyB2CHvAoJqbe1cHNZJSObP'], u'Date and Events[]': [u'2000-09-09', u'bday', u'second']}>`
当我试图访问键为'dateandevents[]的元素时,我只得到列表的最后一个元素。知道为什么会这样吗?在
Tags:
Dict中的\uuGetItem_Uu(),返回该项的原样。可以是int、float、string或list。但QueryDict不是这样。要么你必须使用查询dict.getlist(key)或者把它转换成Dict来完成你的工作。假设'qd'是您想要从中提取项目的QueryDict。在
如果您希望将QueryDict转换为dict,那么您可以执行以下操作来完成您的任务。在
^{pr2}$使用
.getlist(key)
:详细信息:
您的字典属于^{} 类型,它“是一个类似字典的类,可以处理同一个键的多个值。”不幸的是,^{} “只返回最后一个值”。这意味着对
someQueryDict[key]
的调用不会返回列表,即使有多个值与键关联。在解决方案是使用^{} :
相关问题 更多 >
编程相关推荐