views:

432

answers:

1

New to python and django. Using the forms module and going through the errors one by one (so not just dumping them at the top)

I noticed this solution to be able to set a custom format for errors, in my case, it'd be:

<dd class="error">errstr</dd>

And more or less copying the example provided, I have the following:

forms.py ( I expanded it slightly just for my sake)

class DefinitionErrorList(forms.util.ErrorList):

    def __unicode__(self):    
        return self.view_as_dd()

    def view_as_dd(self):
        if not self: 
            return u'' 

        return u'<dd class="error">%s</dd>' % '<br />'.join([u'<span>%s</span>' % e for e in self])

main.py

from poke.forms import PokeForm, DefinitionErrorList

def create_new(response, useless):

    if response.method == 'POST':
        # They posted something, so collect it (duh)

        f = PokeForm(response.POST, error_class=DefinitionErrorList)

        if f.is_valid():
            cd = f.cleaned_data

template for reference

<dt>A small message to remind yourself</dt>
{{ form.message.errors }}
<dd>
    <span class="input_border" style="width: 75%;"> {{ form.message }}</span> 
    <span class="tooltip_span">{{ tooltip.message }}</span>
</dd>

The problem is is that with the above, if a field has an error, it still uses the default format (the ), and no matter what I try I can't get my one to be used. I'm pretty sure I missed something small or misunderstood some instructions.

Thanks for any help and I'm sorry if I forgot any information!

Edit: I'm using Django 1.1, if that helps any. And to make it (possibly) clearer, the errors are displaying fine, they just aren't looking the way I want them to.

+2  A: 

there has been a long lasting ticket on this. http://code.djangoproject.com/ticket/6138

latest update says it's fixed. see if it works in trunk. if not, submit your bug. if it does, get the patch or wait til the next release. (although i thought the latest release was after the date of the last update on the ticket).

Brandon H
Oh, haha. That might be why.Since this is my first project and I'm just learning the basics I'll work around it rather than going for newer versions/patching etc. Thanks for the link though, I decided to just restyle the ErrorList output to look the same as it normally would.
damnitshot