3

I'm new to both Django and Python so please forgive me if I come off as annoying....I'm just very much misinformed!

Error Code: http://i.gyazo.com/68d88cabf536b129dc37cde6c3ae319c.png

I've googled about this 'KeyError' and it seems to be related to clean(). However, the example my lecturer gave me worked ok without it but when I tried to recreate what he gave me I kept getting this error.

A bit of info: I had originally had a ForeignKey for the user for each submission so I changed it to a simple form to fill in (not a permanent solution) but I still get a KeyError.

Here is my models, views and forms:

http://pastebin.com/rAX5PDHQ

Sorry if I left something out. I'll respond ASAP if you all need more info.

Again, sorry if this is a silly question. But I'm utterly lost to be honest.

Thank you!

PS Sorry I really tried the code formatting but I kept getting an error saying it was incorrect thought the preview said it was ok. And I can't post more than one link.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I forgot to say thanks for your reply! I'd overlooked exactly what you said, tis all fixed now. :)
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.

1 Comment

Sorry, I forgot to log in and say thank you! That worked indeed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.