Changed some formatting in docs/middleware.txt

git-svn-id: http://code.djangoproject.com/svn/django/trunk@814 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-10-09 01:08:58 +00:00
parent fd4ddb179f
commit 22bbdc633c
1 changed files with 59 additions and 45 deletions

View File

@ -45,65 +45,79 @@ required.
Available middleware Available middleware
==================== ====================
``django.middleware.admin.AdminUserRequired`` django.middleware.admin.AdminUserRequired
Limits site access to valid users with the ``is_staff`` flag set. This is -----------------------------------------
required by Django's admin, and this middleware requires ``SessionMiddleware``.
``django.middleware.cache.CacheMiddleware`` Limits site access to valid users with the ``is_staff`` flag set. This is
Enables site-wide cache. If this is enabled, each Django-powered page will be required by Django's admin, and this middleware requires ``SessionMiddleware``.
cached for as long as the ``CACHE_MIDDLEWARE_SECONDS`` setting defines. See
the `cache documentation`_.
.. _`cache documentation`: http://www.djangoproject.com/documentation/cache/#the-per-site-cache django.middleware.cache.CacheMiddleware
---------------------------------------
``django.middleware.common.CommonMiddleware`` Enables site-wide cache. If this is enabled, each Django-powered page will be
Adds a few conveniences for perfectionists: cached for as long as the ``CACHE_MIDDLEWARE_SECONDS`` setting defines. See
the `cache documentation`_.
* Forbids access to user agents in the ``DISALLOWED_USER_AGENTS`` setting, .. _`cache documentation`: http://www.djangoproject.com/documentation/cache/#the-per-site-cache
which should be a list of strings.
* Performs URL rewriting based on the ``APPEND_SLASH`` and ``PREPEND_WWW`` django.middleware.common.CommonMiddleware
settings. If ``APPEND_SLASH`` is ``True``, URLs that lack a trailing -----------------------------------------
slash will be redirected to the same URL with a trailing slash. If
``PREPEND_WWW`` is ``True``, URLs that lack a leading "www." will be
redirected to the same URL with a leading "www."
Both of these options are meant to normalize URLs. The philosophy is that Adds a few conveniences for perfectionists:
each URL should exist in one, and only one, place. Technically a URL
``foo.com/bar`` is distinct from ``foo.com/bar/`` -- a search-engine
indexer would treat them as separate URLs -- so it's best practice to
normalize URLs.
* Handles ETags based on the ``USE_ETAGS`` setting. If ``USE_ETAGS`` is set * Forbids access to user agents in the ``DISALLOWED_USER_AGENTS`` setting,
to ``True``, Django will calculate an ETag for each request by which should be a list of strings.
MD5-hashing the page content, and it'll take care of sending
``Not Modified`` responses, if appropriate.
* Handles flat pages. Every time Django encounters a 404 -- either within * Performs URL rewriting based on the ``APPEND_SLASH`` and ``PREPEND_WWW``
a view or as a result of no URLconfs matching -- it will check the settings. If ``APPEND_SLASH`` is ``True``, URLs that lack a trailing
database of flat pages based on the current URL. slash will be redirected to the same URL with a trailing slash. If
``PREPEND_WWW`` is ``True``, URLs that lack a leading "www." will be
redirected to the same URL with a leading "www."
``django.middleware.doc.XViewMiddleware`` Both of these options are meant to normalize URLs. The philosophy is that
Sends custom ``X-View`` HTTP headers to HEAD requests that come from IP each URL should exist in one, and only one, place. Technically a URL
addresses defined in the ``INTERNAL_IPS`` setting. This is used by Django's ``foo.com/bar`` is distinct from ``foo.com/bar/`` -- a search-engine
automatic documentation system. indexer would treat them as separate URLs -- so it's best practice to
normalize URLs.
``django.middleware.gzip.GZipMiddleware`` * Handles ETags based on the ``USE_ETAGS`` setting. If ``USE_ETAGS`` is set
Compresses content for browsers that understand gzip compression (all to ``True``, Django will calculate an ETag for each request by
modern browsers). MD5-hashing the page content, and it'll take care of sending
``Not Modified`` responses, if appropriate.
``django.middleware.http.ConditionalGetMiddleware`` * Handles flat pages. Every time Django encounters a 404 -- either within
Handles conditional GET operations. If the response has a ``ETag`` or a view or as a result of no URLconfs matching -- it will check the
``Last-Modified`` header, and the request has ``If-None-Match`` or database of flat pages based on the current URL.
``If-Modified-Since``, the response is replaced by an HttpNotModified.
Also removes the content from any response to a HEAD request and sets the django.middleware.doc.XViewMiddleware
``Date`` and ``Content-Length`` response-headers. -------------------------------------
``django.middleware.sessions.SessionMiddleware`` Sends custom ``X-View`` HTTP headers to HEAD requests that come from IP
Enables session support. See the `session documentation`_. addresses defined in the ``INTERNAL_IPS`` setting. This is used by Django's
automatic documentation system.
.. _`session documentation`: http://www.djangoproject.com/documentation/sessions/ django.middleware.gzip.GZipMiddleware
-------------------------------------
Compresses content for browsers that understand gzip compression (all modern
browsers).
django.middleware.http.ConditionalGetMiddleware
-----------------------------------------------
Handles conditional GET operations. If the response has a ``ETag`` or
``Last-Modified`` header, and the request has ``If-None-Match`` or
``If-Modified-Since``, the response is replaced by an HttpNotModified.
Also removes the content from any response to a HEAD request and sets the
``Date`` and ``Content-Length`` response-headers.
django.middleware.sessions.SessionMiddleware
--------------------------------------------
Enables session support. See the `session documentation`_.
.. _`session documentation`: http://www.djangoproject.com/documentation/sessions/
Writing your own middleware Writing your own middleware
=========================== ===========================