diff options
| author | Christopher Medrela <chris.medrela@gmail.com> | 2013-11-18 21:16:09 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-02-06 04:45:49 -0500 |
| commit | b22d6c47a7e4c7ab26a8b7b033d11fa6743aae86 (patch) | |
| tree | 986ba5c68e47625c83a6a47482c252327c1e1711 /docs | |
| parent | c43c469a2e4633361f5dccf7dc7ce37054008d18 (diff) | |
Fixed #17005 -- Added CurrentSiteMiddleware to set the current site on each request.
Thanks jordan at aace.org for the suggestion.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/sites.txt | 20 | ||||
| -rw-r--r-- | docs/ref/middleware.txt | 13 | ||||
| -rw-r--r-- | docs/releases/1.7.txt | 6 |
3 files changed, 39 insertions, 0 deletions
diff --git a/docs/ref/contrib/sites.txt b/docs/ref/contrib/sites.txt index b0da9fdabd..36426af5a8 100644 --- a/docs/ref/contrib/sites.txt +++ b/docs/ref/contrib/sites.txt @@ -373,6 +373,26 @@ your admin site to have access to all objects (not just site-specific ones), put ``objects = models.Manager()`` in your model, before you define :class:`~django.contrib.sites.managers.CurrentSiteManager`. +.. _site-middleware: + +Site middleware +=============== + +.. versionadded:: 1.7 + +If you often use this pattern:: + + from django.contrib.sites.models import Site + + def my_view(request): + site = Site.objects.get_current() + ... + +there is simple way to avoid repetitions. Add +:class:`django.contrib.site.middleware.CurrentSiteMiddleware` to +:setting:`MIDDLEWARE_CLASSES`. The middleware sets the ``site`` attribute on +every request object, so you can use ``request.site`` to get the current site. + How Django uses the sites framework =================================== diff --git a/docs/ref/middleware.txt b/docs/ref/middleware.txt index 9799db0865..04ee1fa89e 100644 --- a/docs/ref/middleware.txt +++ b/docs/ref/middleware.txt @@ -179,6 +179,19 @@ Session middleware Enables session support. See the :doc:`session documentation </topics/http/sessions>`. +Site middleware +--------------- + +.. module:: django.contrib.site.middleware + :synopsis: Site middleware. + +.. class:: CurrentSiteMiddleware + +.. versionadded:: 1.7 + +Adds the ``site`` attribute representing the current site to every incoming +``HttpRequest`` object. See the :ref:`sites documentation <site-middleware>`. + Authentication middleware ------------------------- diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index 1bd38d9c8e..e802f257ae 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -358,6 +358,12 @@ Minor features :class:`~django.middleware.http.ConditionalGetMiddleware` to handle conditional ``GET`` requests for sitemaps which set ``lastmod``. +:mod:`django.contrib.sites` +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* The new :class:`django.contrib.site.middleware.CurrentSiteMiddleware` allows + setting the current site on each request. + :mod:`django.contrib.staticfiles` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
