Django Book 翻译
菜单>:
TOC
返回
原文:
A common reason to implement an ``__init__()`` method is to check whether the middleware is indeed needed. If ``__init__()`` raises ``django.core.exceptions.MiddlewareNotUsed`` , then Django will remove the middleware from the middleware stack. You might use this feature to check for some piece of software that the middleware class requires, or check whether the server is running debug mode, or any other such environment situation.
翻译:
对一个middleware而言,定义 ``__init__()`` 方法的通常原因是检查自身的必要性。如果 ``__init__()`` 抛出异常 ``django.core.exceptions.MiddlewareNotUsed`` ,则Django将从middleware栈中移出该middleware。可以用这个机制来检查middleware依赖的软件是否存在、服务是否运行于调试模式、以及任何其它环境因素。
备注:
译者: