Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Djangoシェルセッション中にDjango ORMによって実行された生のSQLクエリの数を出力する方法はありますか?
この種の情報は、Django デバッグ ツールバーによって既に提供されています (たとえば、5 QUERIES in 5.83MSシェルから取得する方法は明らかではありません。
5 QUERIES in 5.83MS
使用できますconnection.queries:
connection.queries
>>> from django.conf import settings >>> settings.DEBUG = True >>> from django.db import connection >>> Model.objects.count() >>> print(len(connection.queries)) 1