只在Django启动一次时执行代码?
from django.core.exceptions import MiddlewareNotUsedfrom django.conf import settingsclass StartupMiddleware(object): def __init__(self): print "Hello world" raise MiddlewareNotUsed('Startup complete')
MIDDLEWARE_CLASSES
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 698Hello world[22/Jul/2011 15:54:36] "GET /static/css/base.css HTTP/1.1" 200 0