0
1

Django DEBUG=FalseでSQLのログを出力する

Last updated at Posted at 2023-12-04

先人の知識から、

を試してみましたが、djangoのバージョンが違うので、動かない・・・

  • django 3.2
  • python 3.9
middleware.py
class UseDebugCursorMiddleware(object):
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        self.process_request(request)
        response = self.get_response(request)

        return response

    def process_request(self, request):
        from django.db import connection

        connection.force_debug_cursor = True
settings.py
MIDDLEWARE = [
    "myapp.middleware.UseDebugCursorMiddleware",
    ・・・

で、多分OK

-               connection.use_debug_cursor = True
+               connection.force_debug_cursor = True

なんですね。

ちなみに、複数のスキーマがあるときには、こんな感じになると思います。

    from django.db import connections
    for connection_name in connections:
        connections[connection_name].force_debug_cursor = True
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1