Re: Error handling. Catching DoesNotExist errors.

2009-06-21 Thread Beals
There's even a shortcut for that! http://www.djangoproject.com/documentation/models/get_or_create/ On Jun 21, 4:03 am, soniiic wrote: > if you'd like to create a book you could have also tried: > > def getBook(request, bookID): > try: >     book = Books.objects.get(id=bookID) > catch Book.DoesN

Re: Error handling. Catching DoesNotExist errors.

2009-06-21 Thread soniiic
if you'd like to create a book you could have also tried: def getBook(request, bookID): try:     book = Books.objects.get(id=bookID) catch Book.DoesNotExist: #create book here return render_to_response('book.html', {'book': book}) Not useful in this situation but I used it in one of my proje

Re: Error handling. Catching DoesNotExist errors.

2009-06-20 Thread Wayne Koorts
> Hah! Incredibly simple! I love Django! I had a few moments like that in the past few days :-) Regards, Wayne --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email

Re: Error handling. Catching DoesNotExist errors.

2009-06-20 Thread Magnus Valle
Hah! Incredibly simple! I love Django! Thank you very much, Wayne! On 21/06/2009, Wayne Koorts wrote: > >> I have a function that looks like this: >> >> def getBook(request, bookID): >>    book = Books.objects.get(id=bookID) >>    return render_to_response('book.html', {'book': book}) >> >> Doe

Re: Error handling. Catching DoesNotExist errors.

2009-06-20 Thread Wayne Koorts
> I have a function that looks like this: > > def getBook(request, bookID): >    book = Books.objects.get(id=bookID) >    return render_to_response('book.html', {'book': book}) > > DoesNotExist at /books/8 > Books matching query does not exist. > > How do I make it redirect to a 404 instead? Ther