Django

Code

Changeset 8254

Show
Ignore:
Timestamp:
08/08/08 17:36:17 (5 months ago)
Author:
jacob
Message:

Fixed #7820: MiddlewareNotUsed? is finally documented somewhere else besides my brain.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/middleware.txt

    r8110 r8254  
    188188Python class that defines one or more of the following methods: 
    189189 
    190 process_request 
    191 --------------- 
     190``process_request`` 
     191------------------- 
    192192 
    193193Interface: ``process_request(self, request)`` 
     
    203203``HttpResponse``. Response middleware is always called on every response. 
    204204 
    205 process_view 
    206 ------------ 
     205``process_view`` 
     206---------------- 
    207207 
    208208Interface: ``process_view(self, request, view_func, view_args, view_kwargs)`` 
     
    223223``HttpResponse``. Response middleware is always called on every response. 
    224224 
    225 process_response 
    226 ---------------- 
     225``process_response`` 
     226-------------------- 
    227227 
    228228Interface: ``process_response(self, request, response)`` 
     
    235235``HttpResponse``. 
    236236 
    237 process_exception 
    238 ----------------- 
     237``process_exception`` 
     238--------------------- 
    239239 
    240240Interface: ``process_exception(self, request, exception)`` 
     
    248248to the browser. Otherwise, default exception handling kicks in. 
    249249 
     250``__init__`` 
     251------------ 
     252 
     253Most middleware classes won't need an initializer since middleware classes are 
     254essentially placeholders for the ``process_*`` methods. If you do need some 
     255global state you may use ``__init__`` to set up. However, keep in mind a couple 
     256of caveats: 
     257 
     258    * Django initializes your middleware without any arguments, so you can't 
     259      define ``__init__`` as requiring any arguments. 
     260       
     261    * Unlike the ``process_*`` methods which get called once per request, 
     262      ``__init__`` gets called only *once*, when the web server starts up. 
     263 
     264Marking middleware as unused 
     265~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     266 
     267It's sometimes useful to determine at run-time whether a piece of middleware 
     268should be used. In these cases, your middleware's ``__init__`` method may raise 
     269``django.core.exceptions.MiddlewareNotUsed``. Django will then remove that piece 
     270of middleware from the middleware process. 
     271 
    250272Guidelines 
    251273----------