For those interested:

In my base template I've added this:

{% load custom_tags %}
{% if form %}
    {% formerrors request form %}
{% endif %}

In my custom_tags template tags library:

@register.simple_tag
def formerrors(request, form):
    for field, errors in form.errors.items():
        for error in errors:
            if field == '__all__':
                messages.error(request, error)
            else:
                messages.error(request, field+': '+error)

    return ''


Works perfectly for me: now all form errors are shown in exactly the
same way as all other messages in my application.

Cheers,
Kevin


On Mar 4, 4:33 pm, Kevin Renskers <i...@bolhoed.net> wrote:
> I'll explain a bit more what precisely it is what I want to do: Django
> 1.2 comes with a new messages framework that allows for each message
> to have a different "level" (succes, error, warning, etc). I want to
> see if a form has errors, and if so, make a message for each error so
> all my notices and errors are displayed in the same way in my
> application.
>
> But I think I just came up with a solution: make a new template tag in
> my base template, always give it the form variable (whether it exists
> or not), and from there create the new messages.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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