I'm trying to return a series of error messages alongside the data
entries in a form. I've evaluated the data in the View and passing the
list of error messages in a render to response request, as follows:
return render_to_response('edit_user_account.html',
{'errordict':errordict,'form':form})
Where errordict is the dictionary containing the keys: user_err,
pw_err and email_err which are added to the dictionary in the View.
View code:
errordict={} #flush error message dictionary
if not check_password_match(password1,password2):
errordict={'pw_err':True}
if username_taken(usernm): #check to see whether user
name already exists
errordict={'user_err':True}
if email_taken(email):
errordict={'email_err':True}
if len(errordict)>0: #if error messages exist, show on
form
return render_to_response('edit_user_account.html',
{'errordict':errordict,'form':form})
My problem is that the template only shows the last error encountered
in my evaluation despite the dictionary containing more than one
entry.
My template html is:
<tr> <td><label for="usernm">Enter Username:</label></
td><td>{{ form.usernm }}</td><td>{% if form.usernm.errors %}***
{{ form.usernm.errors|join:", " }}{% endif %}{% if errordict.user_err
%}The username is already taken.{% endif %}</td></tr>
<tr> <td><label for="password1">Enter Password:</label></
td><td>{{ form.password1 }}</td><td>{% if form.password1.errors %}***
{{ form.password1.errors|join:", " }}{% endif %}{% if errordict.pw_err
%}The passwords do not match.{% endif %}</td></tr>
<tr> <td><label for="password2">Confirm Password:</label></
td><td>{{ form.password2 }}</td><td>{% if form.password2.errors %}***
{{ form.password2.errors|join:", " }}{% endif %}</td></tr>
<tr> <td><label for="email">Enter email address:</label></
td><td>{{ form.email }}</td><td>{% if form.email.errors %}***
{{ form.email.errors|join:", " }}{% endif %}{% if errordict.email_err
%}The email address is already taken.{% endif %}</td></tr>
Can anyone provide any input as to why only one error message appears
in the template despite the dictionary containing several items?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---