Skip to content

Instantly share code, notes, and snippets.

@yheihei
Last active July 20, 2022 12:55
Show Gist options
  • Save yheihei/91e14ddede0da462ed444d288b0d06d5 to your computer and use it in GitHub Desktop.
Save yheihei/91e14ddede0da462ed444d288b0d06d5 to your computer and use it in GitHub Desktop.
djangoでsqlの発行数、発行されたsqlをprintする
from django.conf import settings
from django.db import connection
from django.db import reset_queries
import json
settings.DEBUG = True
reset_queries() # クエリのキューを一旦削除
# 調べたい処理をここに書く
print(json.dumps(connection.queries, indent=4)) # クエリの文字列
print(len(connection.queries)) # クエリの数
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment