728x90
Django ORM에서 SQL 쿼리 확인하는 법
1. Django shell 사용
- Python manage.py shell
- 모델 임포트 (예시: from post.models import Post)
- Post.objects.filter(title=‘안녕하세요’) 테스트
- print(str(Post.objects.filter(title=‘안녕하세요’).query))
2. 로깅모듈 세팅
- settings.py 내 로깅모듈 세팅 (기본 세팅코드 있으니 궁금하시면 전달드릴게요)
3. Django debug toolbar 사용
- https://django-debug-toolbar.readthedocs.io/en/latest/index.html
* 장고 프로젝트에 django-extensions pip로 설치 후 python manage.py shell_plus --ipython으로 장고 쉘을 열어보면 Model import 할 필요 없이 간편하게 바로 ORM 쿼리 확인가능.
728x90
'내배캠 > TIL' 카테고리의 다른 글
TIL/29/20230420 (0) | 2023.04.20 |
---|---|
TIL/28/20230419 (0) | 2023.04.19 |
TIL/26/20230417 (0) | 2023.04.18 |
TIL/25/20230414 (0) | 2023.04.17 |
TIL/24/20230413 (0) | 2023.04.14 |