2011-01-26 88 views

回答

5

中間件:http://docs.djangoproject.com/en/dev/topics/http/middleware/#writing-your-own-middleware

定義一箇中間件類,重寫的上文所定義的功能之一,打印「你好」,(根據文檔)返回適當的對象,並且中間件類添加到你的settings.py

class PrintHelloMiddleware(object): 
    def process_response(self, request, response): 
     print "Hello" 
     return None 

# settings.py 
MIDDLEWARE_CLASSES = (# ... usual middleware 
         'path.to.my.middleware.PrintHelloMiddleware', 
        ) 
+0

代碼的外觀如何?我是否將所有內容都放在__init__中?這個班有什麼功能? – TIMEX 2011-01-26 19:05:24

相關問題