How does Django view SQL statements?

Source: Internet
Author: User
Tags django server django tutorial

DjangoThe database processing is better than a black box. Which of the following operations is completely encapsulated by Django Orm?ProgramThe speed is slow, or you don't know the process in it when you want to debug it. This is a very depressing thing for us. Most programmers have an amazing mentality, they all want to see how it is actually executed. Don't worry. There is a solution below to solve this problem, so you can clearly see it.Django ORMIs the process of executing SQL statements, which is also a number of programs we write.
Specific steps: If you want to knowDjango prints SQL statements, You can see

Here we useDjango MiddlewareThe process_response (self, request, response) method of, the following isCode:
From Django. DB import connection
Def process_response (self, request, response ):
For SQL in connection. queries:
Print SQL
Return response
If you use the built-in Django server, you can see the result in shell.

With this method, you can understand the psychology of running SQL statements on Django.

If you are familiar with Django, we recommend you buy a python host to practice it ..
OriginalArticlePlease note that it is reproduced from Old Wang python. The address of this article is:Http://www.cnpythoner.com/post/118.html

Author: Lao Wang @Python Python tutorial
Old Wang Python provides pythn-relatedPython books, Django tutorial andPython downloadHope you will like it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.