查看Django ORM执行的SQL语句

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

In [2]: User.objects.all()[0]
Out[2]: <User: admin>

In [3]: from django.db import connection

In [4]: connection.queries
Out[4]:
[{'sql': u'SELECT `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_n
ame`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`, `aut
h_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`is_superuser`, `auth_u
ser`.`last_login`, `auth_user`.`date_joined` FROM `auth_user` LIMIT 1',
'time': '0.109'}]

In [5]:

你可能感兴趣的:(查看Django ORM执行的SQL语句)