Exception Type: TypeError  Exception Value: 

catching classes that do not inherit from BaseException is not allowed

 
Did not work.
Get might be faster than filter, but .exact() did not work either

-thanks

perjantai 16. tammikuuta 2015 19.19.09 UTC+2 Mark kirjoitti:
>
> Also, you can do a try/catch, but I don't really like this method, 
> personally:
>
>     try:
>         User.objects.get(username=username)
>     except User.DoesNotExist:
>         # user didn't exist in database.
>
> On Fri, Jan 16, 2015 at 9:16 AM, Mark Furbee <markf...@gmail.com 
> <javascript:>> wrote:
>
>> Yes, that link will cover the basics...
>>
>> Here's a couple ways to find out if a query returns any records:
>>
>>     User.objects.filter(username=username).exists()  # .exists() returns 
>> boolean if records are found.
>>     User.objects.filter(username=username).count() != 0  # .count() 
>> returns number of records in query.
>>     User.objects.filter(username=username).first() is not None # .first() 
>> returns the first record if there are matches, and None if there aren't
>>     
>>
>> On Fri, Jan 16, 2015 at 9:11 AM, James Bennett <ubern...@gmail.com 
>> <javascript:>> wrote:
>>
>>> This may be a good time to review Django's documentation on how to 
>>> perform database queries:
>>>
>>>
>>> https://docs.djangoproject.com/en/1.7/topics/db/queries/#retrieving-a-single-object-with-get
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com <javascript:>.
>>> To post to this group, send email to django...@googlegroups.com 
>>> <javascript:>.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAL13Cg8MaAhTh%2B%3DoGTJ75jeZVY8-gt_hMkUTjZxyLxFkQ%2Bx36Q%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/CAL13Cg8MaAhTh%2B%3DoGTJ75jeZVY8-gt_hMkUTjZxyLxFkQ%2Bx36Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3c382fec-6861-4e91-b9c7-fd3a02e77334%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to