AttributeError: 'list' object has no attribute 'get'
I am using django form. When I submit the form, I get AttributeError: 'list' object has no attribute 'get'
Any idea? thank
def post(self, id=None):
user = self.auth.get_user_by_session()
form = IForm(self.request.POST.items())
if form.is_valid():
UPDATE 2
def post(self, id=None):
user = self.auth.get_user_by_session()
form = IForm(self.request.POST.items())
if form.is_valid():
#I(**form.cleaned_data).put()
k = I()
k.email = 'test@test.com'
k.put()
self.redirect(webapp2.uri_for('list'))
return self.render_template('test_add.html', **template_values)
UPDATE 1
If i use form = IForm(self.request.POST)
then we get> users
Enter a list of values.
The form
class IForm(forms.Form):
email = forms.EmailField(required=False)
users = forms.MultipleChoiceField(required=False, choices=get_my_choices())
I added required=False
. I don't know why the error occurs
source to share
File "/home/sandhu/projects/google_appengine/lib/django_1_3/django/forms/widgets.py", line 178, in value_from_datadict
return data.get(name, None)
AttributeError: 'list' object has no attribute 'get
reports that the data in this case is a list, and of course there is no get () method in the list. the problem is here:
form = IForm(self.request.POST.items())
try to write the results of self.request.POST.items ()
edit: use self.request.POST.items () returns a list of tuples. your forms. Form expects a dictionary. use self.request.POST instead
source to share