Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7822339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:54:13+00:00 2026-06-02T07:54:13+00:00

I know, that in settings, I can have debug = True and all SQL

  • 0

I know, that in settings, I can have debug = True and all SQL queries are logged.

But, I want to log all the SQL queries made by one specific view, before the response is returned.

How can I do this in Django 1.3 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:54:15+00:00Added an answer on June 2, 2026 at 7:54 am

    This can be done by changing logging settings within context of specific view.

    You still need to have DEBUG enabled:

    For performance reasons, SQL logging is only enabled when settings.DEBUG is set to True, regardless of the logging level or handlers that are installed.

    … but you can modify configuration so that only queries by specific view(s) are logged.

    Here’s how it could be done:

    1: In settings.py set django SQL logger (django.db.backends) level to INFO or higher and verify that it stopped recording SQL queries.

    2.a. First line in your view to have SQL logging, set that logger level to DEBUG. Last line, set it back to original value. This is simplest way, but queries executed by middleware before/after view code don’t get logged.

    2.b. Write custom middleware to do the same thing before and after view processing. If you place it first, all queries made by other middlewares will be also logged.

    Note that this method is not thread safe, but since you only want this setup in development environment, this should not matter.


    Django documentation “Logging” chapter:
    https://docs.djangoproject.com/en/1.4/topics/logging/

    Python logging library reference:
    http://docs.python.org/library/logging.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class library that has settings within an app.config. I know that
I know that it's a subject that can raise a lot of debate, but
I know that I should put all the html elements in body tag, but
I have a framework that uses log4net for logging, I know that we can
Currently I have this in my settings.py file: DEBUG = True LOCAL = True
In my web.config I have the standard element; <compilation debug=true defaultLanguage=c#> I know I
I want to know if Netbeans has some option or setting that will allow
I know that exceptions have a performance penalty, and that it's generally more efficient
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
I know that running applications in DEBUG (build configuration) thru the visual studio adds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.