0

Is there a way to time sql queries in Django?

I know there's such thing in dj debug toolbar but I just need to display time on my web-page.

Since I can get a number of queries with:

len(connection.queries)

Maybe there's a similar way to get the time?

1 Answer 1

1

You can show them in templates if you have django.template.context_processors.debug available in your template settings.

It attaches sql_queries list to template.

{% for query in sql_queries %}
    {{ query.time }}
{% endfor %}

Make sure that DEBUG is True in your settings and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS

Of course if you need something more this might help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.