views:

361

answers:

1

One of my forms fails on form.is_valid()

First time I debug a Django form so I am not too sure where to look

forms.py

class ImageForm(forms.ModelForm):
def __init__(self,user,*args,**kwargs):
    super(ImageForm,self ).__init__(*args,**kwargs) # populates the form

class Meta:
    model = KMSImageP
    fields = ('name',
              'caption',
              'image',
              )

models.py

from photologue.models import ImageModel

class KMSImageP(ImageModel):

name = models.CharField(max_length=100)
slug = AutoSlugField(max_length=45, unique=True, populate_from='name')
num_views = models.PositiveIntegerField(editable=False, default=0)
caption = models.TextField(_('caption'), blank

I got that

>>>> image_form.__dict__['_errors']
>>>>django.forms.util.ErrorDict({'image': django.forms.util.ErrorList([<django.utils.functional.__proxy__ object at 0xecc770>])})

So I am guessing that my 'image' field (an ImageField inherited from an abstract base class) is the cause of the failure but I don't know why.

I've tried changing the type of the attributes to FileField (as my other forms use FileField to upload with no problem) but it still fails... Anyhow, I am clueless...

+1  A: 

You really should learn how to use debugger with Django and it's built in server- it has saved me lot's of print/dir expressions and endless edit-run-observe output-edit iterations.

The most basic way to debug python applications is by using pdb It's as easy as dropping in these two lines of code:

import pdb
pdb.set_trace()

in that part of code you want to debug. As soon as the second line is executed, program execution stops at that point and you have to switch to console and you can observe the state and contents of variables, execute next line, go to next breakpoint and so on. Just type ? and press enter. Of course, if you use sophisticated enough IDE debugging is much more easier than this, but this should get you a general idea of how to use debugger.

fest
haven't used pdb yet as I am using werkzeug http://werkzeug.pocoo.org/downloadgreat toolthanks for the tipI'll
PhilGo20
+1 Not real answer, but good tip.
gorsky