Key Error in form.cleaned_data

55 views
Skip to first unread message

Mei B

unread,
Aug 8, 2019, 7:33:59 PM8/8/19
to Django users
I'm using a formset, and i'm trying to iterate through all the cleaned data.... except I keep getting a Keyerror no matter what field I try..

for form in formset:
   data = form.cleaned_data
   name = data["name"]

--->  KeyError: "name"

class VariableForm(forms.Form):
    name = forms.CharField()
    default = forms.CharField(required=False)

Formset = formset_factory(
    VariableForm,
    can_delete=True,
    extra=1,
    )

What is wrong with my code?

I can even print(data) and it outputs:
     {'DELETE': False, 'name': 'PATH', 'default': '/opt/tests'}

I can even do, for key, value in data.items(): and output
    delete false
   name PATH


Reply all
Reply to author
Forward
0 new messages