mirror of
https://github.com/django/django.git
synced 2025-11-18 11:00:24 +00:00
Moved the context processor doc after the middleware one, which seems the place that makes more sense.
This commit is contained in:
parent
91d165f261
commit
1c4b6a93f1
1 changed files with 29 additions and 26 deletions
|
|
@ -39,31 +39,6 @@ the :meth:`request.get_host() <django.http.HttpRequest.get_host>` method.
|
|||
How you use this is up to you, but Django uses it in a couple of ways
|
||||
automatically via a couple of conventions.
|
||||
|
||||
Using ``site`` in templates
|
||||
---------------------------
|
||||
|
||||
.. versionadded:: 6.0
|
||||
|
||||
The current site can be made available in templates through a dedicated
|
||||
context processor.
|
||||
|
||||
Add the :func:`~django.template.context_processors.csp` context processor
|
||||
to your :setting:`TEMPLATES` setting. This makes the current Site object
|
||||
available in the Django templates as the ``site`` context variable::
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
# ...
|
||||
"django.contrib.sites.context_processors.site",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Example usage
|
||||
=============
|
||||
|
||||
|
|
@ -261,9 +236,13 @@ farm out to the template system like so::
|
|||
# ...
|
||||
|
||||
In this case, you'd have to create :file:`subject.txt` and :file:`message.txt`
|
||||
template files that include ``{{ site.name }}`` and ``{{ site.domain }}``.
|
||||
template files for both the LJWorld.com and Lawrence.com template directories.
|
||||
That gives you more flexibility, but it's also more complex.
|
||||
|
||||
It's a good idea to exploit the :class:`~django.contrib.sites.models.Site`
|
||||
objects as much as possible, to remove unneeded complexity and redundancy.
|
||||
|
||||
|
||||
Getting the current domain for full URLs
|
||||
----------------------------------------
|
||||
|
||||
|
|
@ -441,6 +420,30 @@ To avoid repetitions, add
|
|||
:setting:`MIDDLEWARE`. The middleware sets the ``site`` attribute on every
|
||||
request object, so you can use ``request.site`` to get the current site.
|
||||
|
||||
Site context_processor
|
||||
======================
|
||||
|
||||
.. versionadded:: 6.0
|
||||
|
||||
The current site can be made available in templates through a dedicated
|
||||
context processor.
|
||||
|
||||
Add the :func:`~django.template.context_processors.csp` context processor
|
||||
to your :setting:`TEMPLATES` setting. This makes the current Site object
|
||||
available in the Django templates as the ``site`` context variable::
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
# ...
|
||||
"django.contrib.sites.context_processors.site",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
How Django uses the sites framework
|
||||
===================================
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue