from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
class StartupMiddleware(object):
def __init__(self):
print "Hello world"
raise MiddlewareNotUsed('Startup complete')
在我的Django设置文件中,我已经将该类包含在MIDDLEWARE_CLASSES
列表中。
但是当我使用runserver运行Django并请求页面时,在终端中会出现以下内容:
Django version 1.3, using settings 'config.server'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Hello world
[22/Jul/2011 15:54:36] "GET / HTTP/1.1" 200 698
Hello world
[22/Jul/2011 15:54:36] "GET /static/css/base.css HTTP/1.1" 200 0
有什么想法为什么会打印两次“Hello world”?谢谢。