2017-08-13 22 views
0

次のコマンドを使用して、Pythonシェルでユーザーのインスタンスを作成しようとしました。django.contrib.auth.models.DoesNotExist:クエリに一致するユーザーが存在しません

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

この後、次のエラーが発生します。誰かが助けてくれますか?

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. 

答えて

2

あなたはno User with username rohanです。あなたはユーザー名adminのユーザーを持っているようです。

me = User.objects.get(username='admin') 
+0

大丈夫です!私は初心者です。これが私の最初のpythonプロジェクトです。上記のコマンドを使用すると、正確には何が行われますか?あなたは説明していただけますか? –

+0

[このページ](https://docs.djangoproject.com/en/1.11/topics/db/queries/)は、これまでよりも優れていると説明しています。幸運にも、あなたの質問に答えた答えを受け入れてください! –

1

ユーザーのユーザー名は、「管理者」です(クエリセットに表示されています)。

関連する問題