My apologies to the list.

I just noticed the commas at the end of the lines in the views.py
file.

Once I got rid of those, all was much better.



On Feb 7, 11:33 pm, Ben Dembroski <[email protected]> wrote:
> Hi all.
>
> Another silly question.  I'm hoping someone here can explain something
> about the way form validation and processing is working in the
> following example of User Registration:
>
> From forms.py
>
> class RegistrationForm(forms.Form):
>     username = forms.CharField(label=u'Username', max_length=30)
>     email = forms.EmailField(label=u'Email')
>     password1 = forms.CharField(label=u'Password',
> widget=forms.PasswordInput())
>     password2 = forms.CharField(label=u'Repeat Password',
> widget=forms.PasswordInput())
>     fname = forms.CharField(label=u'First Name', max_length=30)
>     lname = forms.CharField(label=u'Last Name', max_length=30)
>
>     def clean_password2(self):
>         if 'password1' in self.cleaned_data:
>             password1 = self.cleaned_data['password1']
>             password2 = self.cleaned_data['password2']
>             if password1 == password2:
>                 return password2
>             else:
>                 raise forms.ValidationError('Passwords do not match.')
>
>     def clean_username(self):
>         username = self.cleaned_data['username']
>         if not re.search(r'^\w+$', username):
>             raise forms.ValidationError('Username can only contain '
>                                         'alphanumeric characters and
> the underscore')
>
>         try:
>             User.objects.get(username=username)
>         except User.DoesNotExist:
>             return username
>         raise forms.ValidationError('Username is already taken.')
>
> The relevant bit of views.py:
>
> form = RegistrationForm(request.POST)
>                 if form.is_valid():
>                         user = User.objects.create_user(
>                                 username=form.cleaned_data['username'],
>                                 password=form.cleaned_data['password1'],
>                                 email=form.cleaned_data['email'],
>                         )
>                         user.first_name=form.cleaned_data['fname'],
>                         user.last_name=form.cleaned_data['lname'],
>                         user.save()
>                         return HttpResponseRedirect('/select')
>
> When I test use the form, and enter a username, password, email, first
> and last name, it creates a user.  However, the saved values for the
> first and last name aren't what I expected:
>
> From manage.py shell:
>
> >>> User.objects.all()
>
> [<User: benjamin>, <User: bob>, <User: newguy>, <User: nexttest>]>>> peep = 
> User.objects.get(username='nexttest')
> >>> peep.first_name
> u"(u'next',)"
> >>> peep.last_name
> u"(u'test',)"
> >>> peep.username
> u'nexttest'
> >>> peep.email
>
> u'[email protected]'
>
>
>
> As you can see, the values for the first_name and last_name are
> unicode strings that represent a tuple?  The other values seem to be
> just fine.
>
> Any explanation on why this is happening?  Or pointers on where to
> look? I've re-read the documentation on forms, the usual googling,
> etc.
>
> This is using version 1.2
>
> Many thanks!
> Ben

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to