Re: Django 1.1.1 - Can't get form validation working
Karen Tracey wrote:
> On Mon, Nov 2, 2009 at 8:55 AM, Andrew <andrew.penrose@gmail.com> wrote:
>> I have a form... as you can see I have "required=True" on the username
>> to test validation
>> class RegistrationForm(forms.Form):
>> username = forms.CharField(required=True),
>> email = forms.EmailField(required=True),
>> password1 = forms.CharField(required=True),
>> password2 = forms.CharField(required=True),
>>
>
> You do not need all the required=True, that is the default. Also you have
> commas on the end of all these lines, get rid of them.
> For reasons I do not
> have time to figure out, they cause problems. They are not supposed to be
> there.
> Commas are good on the ends of elements in a sequence, they are not
> good here.
Indeed, a comma at the end actively denotes a kind of sequence, a matter
of python syntax. There won't be an immediate error as "blah," means
"1-element tuple" as per
http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
i.e.
username = forms.CharField(),
means
username = (forms.CharField(),)
So the assignment succeeds without error but django later won't do
anything especially useful with username during inspection of the form
definition as it'll look at it and go "nope, this ain't a django
formfield, just some tuple"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home