Skip to content

Instantly share code, notes, and snippets.

@wonderer80
Last active February 9, 2022 02:42
Django shell 에서 queryset 실행 될 때 SQL을 콘솔 출력하기
from django.test.utils import CaptureQueriesContext
from django.db import connections
from contextlib import ExitStack
import logging
logger = logging.getLogger('django.db.backends')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
for connection in connections.all():
CaptureQueriesContext(connection).__enter__()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment