I think the errors attribute needs to be a list (hence the name), so try: form._errors['name'].append('User name already in use')
I think errors is not only a list, but an instance of django.forms.utils.ErrorList (or any subclass of it), which controls the way errors are displayed in the form, as noted here: http://docs.djangoproject.com/en/dev/ref/forms/api/#customizing-the-error-list-format Now that I had a look at the source, there is an ErrorDict too, not sure what gets used when, but it should be irrelevant to your problem. Regards, Reiner On May 22, 10:42 pm, CrabbyPete <pete.do...@gmail.com> wrote: > If I have a form and if form.is_valid is False > > The code code in the template {{ form.name.errors}} formats the error > like this. > <div><ul class="errorlist"><li>This field is required.</li></ul></div> > > How do you add an error so it gets formatted with the surrounding > html. If a user name already exists I want to add the error message > 'User name already in use' > > I tried form._errors[name] = 'User name already in use' and > {{form.name.errors}} just prints the string. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---