In my views.py, i have a snippit of code like this:
def clean_post_data(form): for i in form.cleaned_data: form.cleaned_data[i] = form.cleaned_data[i].rstrip() def add_product(request): form = ProductForm(request.POST, request.FILES or None) image = Image.objects.all() action = 'Add' if request.POST: if form.is_valid(): clean_post_data(form) form.save() action = 'Added new product' return render_to_response('cms/admin/action.html', {'action' : action},context_instance=RequestContext(request)) else: action = 'There was an error. Please go back and try again' return render_to_response('cms/admin/action.html', {'action' : action}, context_instance=RequestContext(request)) return render_to_response('cms/admin/editproduct.html', {'form' : form, 'action' : action, 'image' : image}, context_instance=RequestContext(request))
But when i run that, i get the following error 'list' object has no attribute 'rstrip'. What am i doing wrong.
I originally had the for i in form.cleaned_data: loop directly in the view (not in another function) and it worked fine, but now when i try it i get the same error as above. http://dpaste.com/92836/
The
clean_post_datashouldn’t be a stand-alone function.It should be a method in the form, named
clean. See Form and Field Validation.