On Thu, 2009-02-12 at 20:15 -0800, waltbrad wrote:
> I'm going through Sam's 24 hour.  I've looked at this code for hours
> now, starting from about a week ago. I decided it wasn't that
> important and moved on. But now the author keeps referring back to
> this view and it hampers my continuing the code. It basically just
> adds a blog object as an attribute of a Person object.  Here is the
> entire view:
> 
> http://dpaste.com/120042/
> 
> But when I try to post the blog I get the error:
> 
> 'Database Error'.
> 
> So, that seems to indicate that the saveform.is_valid condition is
> true but the "try" hit an exception.  Which means that there is
> something wrong with the following four lines of code after the try:
> 
> try:
>      bObj = saveform.save()
>      p.blogs.add(bObj)
>      p.save()
>      message = 'Blog added to %s. ' % p.name
> 
> There is something about this code that seems redundant, but the
> saveform.save() is for the database entry for the blog model.  The
> p.save() just links the blog as an attribute of the Person in the db.
> So, the code seems to be fine.

The code you've pointed to makes debugging very hard. It completely
hides all the details of the exception. The first thing I would try
would be removing the "try" and"except" statements. If an exception
occurs, see what it is and what the traceback looks like.

Alternatively, you could change the except to :

        except Exception, e:
           ...
        
so you at least can work with the exception object(e.g. print out)
and/or you can import the traceback module and use things like
traceback.print_exc to see what's going on. As written, though, the code
isn't helping you debug at all. Rather than guessing what the problem
might be, it will be more useful to find out what it actually is (let
Python tell you, via the traceback).

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to