您的位置:首页 > 产品设计 > UI/UE

django.utils.datastructures.MultiValueDictKeyError

2018-10-16 18:00 841 查看
django.utils.datastructures.MultiValueDictKeyError: 'a'

源代码如下

print(request.GET['a'])

其实就是在 request.Post/Get 时,提取的 Key 不存在导致的

QueryDict.getitem(key)¶
Returns the value for the given key. If the key has more than one value, it returns the last value. Raises django.utils.datastructures.MultiValueDictKeyError if the key does not exist. (This is a subclass of Python’s standard KeyError, so you can stick to catching KeyError.)

解决办法:

1.使用QueryDict.get()方法
2.先判断Key是否存在,然后获取
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Django DictKey Error
相关文章推荐