form object has no attribute 'cleaned_data'

1,743 views
Skip to first unread message

jeff

unread,
Apr 1, 2010, 12:09:37 AM4/1/10
to Django users
so i've searched high and low on this error. lots of answers about
having used old versions of django. i did this:

j@earth:/home/samba/raymour/v1/rrsite$ django-admin.py --version
1.1.1

then a lot of stuff about python path having been done with an easy
installer and having an 'egg' in it. doesn't seem i have that problem:

['/home/samba/ray/v1/rrsite', '/usr/lib/python2.6', '/usr/lib/
python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/
python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/
python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/Numeric',
'/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-
packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/
python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/
gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.6-gtk2-unicode', '/
usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode', '/usr/local/lib/
python2.6/dist-packages']

i just used the version on ubuntu.

here is my form:
from django import forms

class SymForm(forms.Form):
sym1=forms.CharField()
sym2=forms.CharField()

and view:
def add_pair(request):
# these are the basic locals we need to set for the template to
populate
page_title='Add a Pair'
if request.method == 'POST':
form=SymForm(request.POST)
if form.is_valid:
s1=form.cleaned_data['sym1'] #form.cleaned_data['subject']
#s2=form.clean_sym2
s=Pair(sym1=s1,sym2=s2)
s.save()
return HttpResponseRedirect('/sym/added/')

please can you offer any suggestions???

thanks in advance.


and the traceback:
Environment:

Request Method: POST
Request URL: http://192.168.1.80:8080/add/pair/
Django Version: 1.1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'rrsite.pairs01']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in
get_response
92. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/samba/ray/v1/rrsite/../rrsite/pairs01/views.py" in
add_pair
38. s1=form.cleaned_data['sym1']
#form.cleaned_data['subject']

Exception Type: AttributeError at /add/pair/
Exception Value: 'SymForm' object has no attribute 'cleaned_data'

Nick Arnett

unread,
Apr 1, 2010, 12:13:54 AM4/1/10
to django...@googlegroups.com
On Wed, Mar 31, 2010 at 9:09 PM, jeff <jeff...@gmail.com> wrote:

       page_title='Add a Pair'
       if request.method == 'POST':
               form=SymForm(request.POST)
               if form.is_valid:

is_valid is a call - you want this:

if form.is_valid():

Nick
Reply all
Reply to author
Forward
0 new messages