1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Djangoのユーザをシェルで確認

Last updated at Posted at 2018-12-15

こちらの記述を参考にしました。
Djangoのユーザをシェルで確認する方法

GUI で見ると次のように見えるユーザーをシェルで確認します。
user_dec15.png

manage.py のあるフォルダーで次のように実行します。

$ python manage.py shell
Python 3.7.1 (default, Oct 22 2018, 10:41:28) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from django.contrib.auth.models import User                             

In [2]: for user in User.objects.all(): 
   ...:     print(user.id,user.username,user.email) 
   ...:                                                                         
1 admin test@test.com
2 test01 
3 test02 
4 test03 

In [3]: quit

データベースに直接アクセスして確認するとこうなります。

$ python manage.py dbshell
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 63
Server version: 10.5.12-MariaDB-1build1 Ubuntu 21.10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [django]> select id,username,email from auth_user;
+----+----------+---------------+
| id | username | email         |
+----+----------+---------------+
|  1 | admin    | test@test.com |
|  2 | test01   |               |
|  3 | test02   |               |
|  4 | test03   |               |
+----+----------+---------------+
4 rows in set (0.00 sec)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?