mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #17005 -- Added CurrentSiteMiddleware to set the current site on each request.
Thanks jordan at aace.org for the suggestion.
This commit is contained in:
parent
c43c469a2e
commit
b22d6c47a7
5 changed files with 60 additions and 0 deletions
|
@ -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
|
||||
===================================
|
||||
|
||||
|
|
|
@ -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
|
||||
-------------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue