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
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
> 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
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
> 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
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})
bookID is a \d. In a url like this www.example.com/books/8 bookID will
be 8. And the the page response will be the 8th book in
6 matches
Mail list logo