Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7820: MiddlewareNotUsed is finally documented somewhere else b…

…esides my brain.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8254 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b30ee21dc122c22d08e19e5a95d510688f105fa5 1 parent 097a19c
Jacob Kaplan-Moss authored August 08, 2008

Showing 1 changed file with 30 additions and 8 deletions. Show diff stats Hide diff stats

  1. 38  docs/middleware.txt
38  docs/middleware.txt
@@ -187,8 +187,8 @@ Writing your own middleware
187 187
 Writing your own middleware is easy. Each middleware component is a single
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)``
194 194
 
@@ -202,8 +202,8 @@ an ``HttpResponse`` object, Django won't bother calling ANY other request,
202 202
 view or exception middleware, or the appropriate view; it'll return that
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)``
209 209
 
@@ -222,8 +222,8 @@ Django will continue processing this request, executing any other
222 222
 or exception middleware, or the appropriate view; it'll return that
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)``
229 229
 
@@ -234,8 +234,8 @@ object returned by a Django view.
234 234
 the given ``response``, or it could create and return a brand-new
235 235
 ``HttpResponse``.
236 236
 
237  
-process_exception
238  
------------------
  237
+``process_exception``
  238
+---------------------
239 239
 
240 240
 Interface: ``process_exception(self, request, exception)``
241 241
 
@@ -247,6 +247,28 @@ Django calls ``process_exception()`` when a view raises an exception.
247 247
 object. If it returns an ``HttpResponse`` object, the response will be returned
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
 ----------
252 274
 

0 notes on commit b30ee21

Please sign in to comment.
Something went wrong with that request. Please try again.