Skip to content

Instantly share code, notes, and snippets.

@wonderer80
Last active February 9, 2022 02:42
Show Gist options
  • Save wonderer80/b42f2dfb638a9a289c8bd1daab198bf9 to your computer and use it in GitHub Desktop.
Save wonderer80/b42f2dfb638a9a289c8bd1daab198bf9 to your computer and use it in GitHub Desktop.
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