Categories
Python Answers

How to view corresponding SQL query of the Python Django ORM’s queryset?

Spread the love

To view corresponding SQL query of the Python Django ORM’s queryset, we can use the query property of the query set.

For instance, we write

qs = Model.objects.filter(name='test')
print(qs.query)

to print the SQL query corresponding to the Model.objects.filter(name='test') queryset with

print(qs.query)

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *