django.contrib.auth.models.DoesNotExist: User matching query does not exist
12,132
Solution 1
You have no User with username rohan. You seems to have a user with username admin though.
me = User.objects.get(username='admin')
Solution 2
Your user's username is "admin", as seen in the queryset.
Related videos on Youtube
Author by
Rohan Jain
Updated on June 04, 2022Comments
-
Rohan Jain almost 2 years
I tried to create an instance of a user in python shell using the following commands.
from django.contrib.auth.models import User User.objects.all() <QuerySet [<User: admin>]> me = User.objects.get(username='rohan')
After which I got the following errors. Can someone please help.
Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\query.py", line 380, in get self.model._meta.object_name django.contrib.auth.models.DoesNotExist: User matching query does not exist.
-
Rohan Jain over 6 yearsalright! I am a beginner and this is my first python project. when I use the above command what exactly does it do? Can you please explain.
-
D.Nibon over 6 yearsThis page explains it better then I ever could. Good luck and please accept the answer that answered your question!
-
help-info.de over 4 yearsThere are other answers that provide the OP's question, and they were posted some time ago. When posting an answer, please make sure you add either a new solution, or a substantially better explanation, especially when answering older questions.