[Django]-Getting KeyError in my django code

1👍

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.

👤Selcuk

1👍

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.

Leave a comment