from django.db import connection
queryset = Model.objects.filter()
queryset[0] # This variant needs the queryset to be accessed. Hence.
print connection.queries
If you want to print the queries used to render a page then you can use the toolbar as @Meitham suggested or use this Django snippet.
Certainly. From the command line/shell:
Variant 2:
If you want to print the queries used to render a page then you can use the toolbar as @Meitham suggested or use this Django snippet.
You can decorate a request handler or other function with this and it will print the sql nicely formated with totals at the end.