Getting KeyError in my django code

此生再无相见时 提交于 2019-12-06 00:30:28

You don't have a field named user in your form. Try changing the relevant line to:

 bd = BloodData  (respondent=cd['respondent'],

in your "storeBloodData" view.

The problem seems to be in your view storeBloodData,at this point.

bd = BloodData  (respondent=cd['user'],

The form has no field named 'user'.You may replace it with a relevant field present declared in the form.

Also, it is better to use DICT.get(key)when you are not sure if the dict contains that particular key or not. This way you'll simply be returned None when the key is absent and you'll be able to dodge KeyError.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!