Search code examples
pythondjangokeyerror

Getting KeyError in my django code


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.


Solution

  • 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.