Answer the question
In order to leave comments, you need to log in
Why does 'NoneType' object has no attribute 'user' error?
For some reason, the object becomes NoneType even though there is a check before that:
urls = Info.objects.filter(url=url)
if urls is not None:
if urls.first().user != request.user:
Answer the question
In order to leave comments, you need to log in
if urls is not None
- always True because it .filter(url=url)
returns a Queryset - it's always not None.
Use Info.objects.filter(url=url).first()
- to get an object or None
If you need to check if there is something in the queryset use .exists()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question