How to print requests executed by dsango.save () method?

I want to see what requests are executed for the dsango.save () method. Since I'm in production, I can't use the Django toolbar for this.

+6
source share
2 answers

There are two ways:

There seems to be no simple direct path without DEBUG = True. This is the closest I could find: Running Django SQL queries with DEBUG set to False

+2
source

Based on Sid's answer and this snippet (http://djangosnippets.org/snippets/1973/), I replace the postgres dg wrapper with the following:

# base.py from django.db.backends.postgresql_psycopg2.base import * #http://djangosnippets.org/snippets/1973/ class DatabaseWrapper(DatabaseWrapper): def __init__(self, *args, **kwargs): super(DatabaseWrapper, self).__init__(*args, **kwargs) self.use_debug_cursor = True 

Then in settings.py use 'ENGINE': 'my_project.db_backend' instead of the default backend (in my case, 'ENGINE': 'django.db.backends.postgresql_psycopg2' ,)

Now connection.queries will contain all your queries!

+4
source

Source: https://habr.com/ru/post/911867/


All Articles