Maison > Article > développement back-end > Comment enregistrer toutes les requêtes SQL dans Django ?
Logging all SQL queries executed by a Django application can be beneficial for debugging and performance analysis. This article provides a step-by-step guide on how to achieve this effectively.
To log all SQL queries, including those generated by the admin site, integrate the following snippet into the LOGGING field within your settings.py file:
<code class="python">LOGGING = { 'version': 1, 'filters': { 'require_debug_true': { '()': 'django.utils.log.RequireDebugTrue', } }, 'handlers': { 'console': { 'level': 'DEBUG', 'filters': ['require_debug_true'], 'class': 'logging.StreamHandler', } }, 'loggers': { 'django.db.backends': { 'level': 'DEBUG', 'handlers': ['console'], } } }</code>
Upon implementation, all SQL queries performed by your Django application will be recorded in the specified log file, providing a comprehensive record of database interactions for troubleshooting and analysis.
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!