Re:Learn web development: Django Web Framework
by vivekd on Saturday February 11, 2017 @02:00AM
(#13621503)
wait just tried the code again, you were right, I don't need the second empty string. I was using [] with get and it wasn't working.
so it seems the right way is form.cleaned_data.get('formfieldvalue')
or
form.cleaned_data[formfieldvalue']
if you don't want to use get
I just tried your solution with cleaned_data["formfield1"] instead of cleaned_data("formfield1","") and it didn't work for me, it came back with the following error message when I submitted the form:
>'builtin_function_or_method' object is not subscriptable
I think you have to have the empty quotes after the form field and I think that's what's capturing the user input
so here "form.cleaned_data("formfield1","") seems to be telling django the form name and then the second field is where the associated user input goes which is then passed to the model.