On Mon, Nov 2, 2009 at 8:55 AM, Andrew <andrew.penr...@gmail.com> wrote:

>
> [snip]
> Here is the scenario....
> I am doing a simple registration form...
>
> 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.



>
> I have a pattern in my url.py as you do...
>    (r'^register/$','myproject.views.register'),
>
> I have a method in my view that takes the post...
> def register(request):
>    if request.user.is_authenticated():
>        return HttpResponseRedirect("/")
>    result = ""
>    if request.method == 'POST':
>        form = RegistrationForm(request.POST)
>        if form.is_valid():
>            result = True
>        else:
>            result = False
>
>    else:
>        form = RegistrationForm()
>    form = RegistrationForm()
>

Get rid of this last form = RegistrationForm().  It's causing an empty
unbound form to get sent to the template for rendering, regardless of what
path you went through above.  As a result you will never be able to see what
errors caused form validation to fail (and it will fail when you get rid of
the commas above).


>    return render_to_response('pages/account/account.html', {'form':
> form,'result':result,})
>
>
>From the template, you do not need all of the {% if %} blocks like this:

       {% if form.username.errors %}
       {{ form.username.html_error_list }}
       {% endif %}

Where did html_error_list come from?  Near as I can tell bound fields don't
have this attribute, so this will print nothing even when errors exist.
These blocks should all just be like:

{{ form.username.errors }}

which will print nothing if there are no errors, and an HTML unordered list
of errors if there are any.

Also, {% if form.error_dict %} should be simply {% if form.errors %}.

Karen

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to