django.contrib.auth.models.DoesNotExist:用户匹配查询不存在

Roh*_*ain 0 django django-models python-3.6

我试图使用以下命令在python shell中创建用户实例。

from django.contrib.auth.models import User
User.objects.all()
<QuerySet [<User: admin>]>
me = User.objects.get(username='rohan')
Run Code Online (Sandbox Code Playgroud)

之后,我得到以下错误。有人可以帮忙吗?

 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.
Run Code Online (Sandbox Code Playgroud)

D.N*_*bon 6

您没有使用用户名rohan的用户。您似乎有一个用户名为admin的用户。

me = User.objects.get(username='admin')
Run Code Online (Sandbox Code Playgroud)