Skip to content

Instantly share code, notes, and snippets.

@maheshgawali
Created May 11, 2018 07:55
Show Gist options
  • Save maheshgawali/de79e42104114619bcf1e970abb501da to your computer and use it in GitHub Desktop.
Save maheshgawali/de79e42104114619bcf1e970abb501da to your computer and use it in GitHub Desktop.
Django: show/log ORM sql calls from python shell
# taken from -> https://stackoverflow.com/a/30394237/1035818
# i hunt for this every once in a while, so creating the gist, all credits for this snippet at to the commenter from the link above
import logging
from django.db import connection
connection.force_debug_cursor = True # Change to use_debug_cursor in django < 1.8
l = logging.getLogger('django.db.backends')
l.setLevel(logging.DEBUG)
l.addHandler(logging.StreamHandler())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment