简体   繁体   English

django请求处理程序是什么callback()

[英]what is django request handler callback()

I'm looking at the base handler for http requests in Django 1.4 (base.py, https://github.com/django/django/blob/stable/1.4.x/django/core/handlers/base.py#L109 ). 我正在寻找Django 1.4中http请求的基本处理程序(base.py, https://github.com/django/django/blob/stable/1.4.x/django/core/handlers/base.py#L109 )。

After the code has cycled through the request middleware and the view middleware, you can see it checks one more time if response is None at line 107. Then it tries to run the callback() function (line 109). 在代码遍历请求中间件和视图中间件之后,如果在第107行response is None ,则可以看到它再次检查了一次。然后,它尝试运行callback()函数(第109行)。 I would like to know where this method is defined. 我想知道在哪里定义此方法。 I'm looking at the stack trace for an error and after this method is called the next line in the trace is for a file that doesn't exist in my dev environment (where the error is not occurring). 我正在查看堆栈跟踪中是否有错误,并且在调用此方法后,跟踪中的下一行是针对我的开发环境中(不发生错误)不存在的文件的。 So, clearly, this callback() does something I'm not familiar with. 因此,很明显,这个callback()做了我不熟悉的事情。 Is this a configuration setting, python keyword, or something? 这是配置设置,python关键字还是其他?

How does Django/python decide what to do when it reaches callback() at line 109? 当Django / python在第109行到达callback()时,如何决定该怎么做?

callback is the view from your urls.py that matches the url you are accessing. callback是您urls.py中与您正在访问的URL匹配的视图。 Django gets this callback by calling resolver.resolve (in the Django 1.4 version of the file you linked to, this happens on line 98 ). Django通过调用resolver.resolve获取此callback (在链接到的文件的Django 1.4版本中,这发生在第98行 )。

In Python, functions are objects, so resolver.resolve can return a function that can be called later. 在Python中,函数是对象,因此resolver.resolve可以返回一个以后可以调用的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM