Menu Close

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

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)
Posted in Python, Python Answers