Changeset 8254
- Timestamp:
- 08/08/08 17:36:17 (5 months ago)
- Files:
-
- django/trunk/docs/middleware.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/middleware.txt
r8110 r8254 188 188 Python class that defines one or more of the following methods: 189 189 190 process_request 191 --------------- 190 ``process_request`` 191 ------------------- 192 192 193 193 Interface: ``process_request(self, request)`` … … 203 203 ``HttpResponse``. Response middleware is always called on every response. 204 204 205 process_view 206 ------------ 205 ``process_view`` 206 ---------------- 207 207 208 208 Interface: ``process_view(self, request, view_func, view_args, view_kwargs)`` … … 223 223 ``HttpResponse``. Response middleware is always called on every response. 224 224 225 process_response 226 ---------------- 225 ``process_response`` 226 -------------------- 227 227 228 228 Interface: ``process_response(self, request, response)`` … … 235 235 ``HttpResponse``. 236 236 237 process_exception 238 ----------------- 237 ``process_exception`` 238 --------------------- 239 239 240 240 Interface: ``process_exception(self, request, exception)`` … … 248 248 to the browser. Otherwise, default exception handling kicks in. 249 249 250 ``__init__`` 251 ------------ 252 253 Most middleware classes won't need an initializer since middleware classes are 254 essentially placeholders for the ``process_*`` methods. If you do need some 255 global state you may use ``__init__`` to set up. However, keep in mind a couple 256 of 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 264 Marking middleware as unused 265 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 266 267 It's sometimes useful to determine at run-time whether a piece of middleware 268 should be used. In these cases, your middleware's ``__init__`` method may raise 269 ``django.core.exceptions.MiddlewareNotUsed``. Django will then remove that piece 270 of middleware from the middleware process. 271 250 272 Guidelines 251 273 ----------
