Where can I get technical information on how Django's inside works?

Where can I get technical manuals / details about how django internal components work, that is, I would like to know when the request comes from the client,

  • what django function gets?
  • What is called middleware?
  • How is a request object created? and which class / function creates it?
  • Which function displays the request for the desired view?
  • How do you call your code / view

? etc...

Paul.G

+7
python django
source share
6 answers

The easiest way to understand the insides of a django is to read a book specially written for this.

Read Pro Django . It gives you a deep understanding of meta programming and demonstrates how it is used in django models to create them dynamically.

It works similarly to many other python concepts and how django uses it.

+9
source share

Besides reading the source, here are a few articles that I tagged and bookmarked a bit earlier:

I found a James Bennett blog to be a great source of information on django's work. His book, Django Practical Projects , should also be read - although it is not internally oriented, you will still learn how django works.

+12
source share

"Use the source, Luke." The beauty of open source software is that you can view (and modify) the code yourself.

+10
source share

Just reading the source can be a bit overwhelming, especially since the very top is a bit confusing (like the web server is requesting Django code). I believe that a good way to start reading code is to set the debugger breakpoint in your view function:

def time(request): import pdb; pdb.set_trace() return HttpResponse(blah blah) 

then click the URL. When the debugger breaks into a breakpoint, look at the stack:

 (Pdb) where c:\abcxyzproject\django\core\management\commands\runserver.py(60)inner_run() -> run(addr, int(port), handler) c:\abcxyzproject\django\core\servers\basehttp.py(698)run() -> httpd.serve_forever() c:\python25\lib\socketserver.py(201)serve_forever() -> self.handle_request() c:\python25\lib\socketserver.py(222)handle_request() -> self.process_request(request, client_address) c:\python25\lib\socketserver.py(241)process_request() -> self.finish_request(request, client_address) c:\python25\lib\socketserver.py(254)finish_request() -> self.RequestHandlerClass(request, client_address, self) c:\abcxyzproject\django\core\servers\basehttp.py(560)__init__() -> BaseHTTPRequestHandler.__init__(self, *args, **kwargs) c:\python25\lib\socketserver.py(522)__init__() -> self.handle() c:\abcxyzproject\django\core\servers\basehttp.py(605)handle() -> handler.run(self.server.get_app()) c:\abcxyzproject\django\core\servers\basehttp.py(279)run() -> self.result = application(self.environ, self.start_response) c:\abcxyzproject\django\core\servers\basehttp.py(651)__call__() -> return self.application(environ, start_response) c:\abcxyzproject\django\core\handlers\wsgi.py(241)__call__() -> response = self.get_response(request) c:\abcxyzproject\django\core\handlers\base.py(92)get_response() -> response = callback(request, *callback_args, **callback_kwargs) > c:\abcxyzproject\abcxyz\helpers\views.py(118)time() -> return HttpResponse( (Pdb) 

Now you can see a summary of the path from the deepest part of the web server to the view function. Use the up command to move up the stack, and the list and print command to check the code and variables in these stack frames.

+6
source share

I doubt that there are technical manuals on this. This may take some time, but the API documentation and source code are your best bet for reliable and up-to-date information.

+1
source share

Documentation is often detailed when needed to explain why everything works the way they do. One of the goals of Django's design is to not rely on β€œmagic” as much as possible. However, whenever Django does something (placing templates in applications, for example), it clearly explains why in the documentation, and this always happens predictably.

Most of your questions will be answered in one page.

  • The request is created by the client for a specific URL.
  • The URL allows what kind of call based on the pattern of the URL.
  • The request is transmitted through middleware.
  • The request object is called and explicitly passed.
  • The view explicitly indicates the template that you specify, and passes the context (variables) you specify to it.
  • Template context processors, if any, then add their own variables to the context.
  • The context is passed to the template and rendered.
  • The resulting template is returned to the client.

Django Documentation

Django book

0
source share

All Articles