On Wed, Mar 21, 2007 at 04:47:35PM -0700, Gerard M wrote:
> 
> Hello django community, I have a HUGE problem, and I would like to
> know if some of you guys can help me, the problem is: Im accesing a
> database and there is a big chance of not finding the item im looking
> for, this is the snipplet of code im using and the "solution" that
> I've implemented but it doesn't work as it should:
> 
> from django.core.exceptions import ObjectDoesNotExist
> 
> try:
>      z=Dic.objects.filter(DB_Word=worfromtext).distinct()
>      print z
> except ObjectDoesNotExist:
>     print 'ERROR!'

Try using Dic.objects.get( ... ) instead of filter( ... ).

filter gives you a subset of the table.  get gives you a single result.  filter
doesn't mind giving you an empty result.  get assumes you wanted exactly one
result, and raises an exception (Dic.DoesNotExist) if the object doesn't exist.

Hope this helps.

-Forest

Attachment: signature.asc
Description: Digital signature

Reply via email to