Last active
February 9, 2022 02:42
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