从 executemany(sql, params) django/postgresql 获取原始查询

Get the raw query from executemany(sql, params) django/postgresql

如何从 cursor.executemany(sql, params) 获取原始查询?

我是 运行 一个不起作用的查询,我想在它被游标格式化后查看查询。谢谢

一个选项是打开 django.db.backends logging extension:

Messages relating to the interaction of code with the database. For example, every application-level SQL statement executed by a request is logged at the DEBUG level to this logger.

其中一个优点是您无需对代码进行任何更改 - 只需对 settings.py 配置进行更改。一个好主意是在开发过程中打开它。