方式一:
使用print打印时在queryset对象后使用.query
book_qs = models.Book.objects.filter(pk=1).values('publish__name','title') print(book_qs.query)
book_qs = models.Book.objects.filter(pk=1).values('publish__name','title') print(book_qs.query)
打印结果:
SELECT `app01_publish`.`name`, `app01_book`.`title` FROM `app01_book` INNER JOIN `app01_publish` ON (`app01_book`.`publish_id` = `app01_publish`.`id`) WHERE `app01_book`.`id` = 1
方式二:
在settings文件内配置:
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console':{ 'level':'DEBUG', 'class':'logging.StreamHandler', }, }, 'loggers': { 'django.db.backends': { 'handlers': ['console'], 'propagate': True, 'level':'DEBUG', }, } }
后续直接print直接打印需要查看sql语句的queryset对象即可
标签:语句,qs,打印,publish,orm,app01,sql,print,book From: https://www.cnblogs.com/wellplayed/p/17878324.html