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.
Ned batchelder
source share