Last active
February 9, 2022 02:42
-
-
Save wonderer80/b42f2dfb638a9a289c8bd1daab198bf9 to your computer and use it in GitHub Desktop.
Django shell 에서 queryset 실행 될 때 SQL을 콘솔 출력하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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