mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #26601 -- Improved middleware per DEP 0005.
Thanks Tim Graham for polishing the patch, updating the tests, and writing documentation. Thanks Carl Meyer for shepherding the DEP.
This commit is contained in:
parent
05c888ffb8
commit
9baf692a58
81 changed files with 900 additions and 1414 deletions
|
@ -175,13 +175,14 @@ the most likely choices.
|
|||
Here's an example that stores the current timezone in the session. (It skips
|
||||
error handling entirely for the sake of simplicity.)
|
||||
|
||||
Add the following middleware to :setting:`MIDDLEWARE_CLASSES`::
|
||||
Add the following middleware to :setting:`MIDDLEWARE`::
|
||||
|
||||
import pytz
|
||||
|
||||
from django.utils import timezone
|
||||
from django.django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
class TimezoneMiddleware(object):
|
||||
class TimezoneMiddleware(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
tzname = request.session.get('django_timezone')
|
||||
if tzname:
|
||||
|
|
|
@ -38,7 +38,7 @@ make some optimizations so as not to load the internationalization machinery.
|
|||
.. note::
|
||||
|
||||
Make sure you've activated translation for your project (the fastest way is
|
||||
to check if :setting:`MIDDLEWARE_CLASSES` includes
|
||||
to check if :setting:`MIDDLEWARE` includes
|
||||
:mod:`django.middleware.locale.LocaleMiddleware`). If you haven't yet,
|
||||
see :ref:`how-django-discovers-language-preference`.
|
||||
|
||||
|
@ -1422,7 +1422,7 @@ Django provides two mechanisms to internationalize URL patterns:
|
|||
Using either one of these features requires that an active language be set
|
||||
for each request; in other words, you need to have
|
||||
:class:`django.middleware.locale.LocaleMiddleware` in your
|
||||
:setting:`MIDDLEWARE_CLASSES` setting.
|
||||
:setting:`MIDDLEWARE` setting.
|
||||
|
||||
Language prefix in URL patterns
|
||||
-------------------------------
|
||||
|
@ -2065,8 +2065,8 @@ prefer, then you also need to use the ``LocaleMiddleware``.
|
|||
It customizes content for each user.
|
||||
|
||||
To use ``LocaleMiddleware``, add ``'django.middleware.locale.LocaleMiddleware'``
|
||||
to your :setting:`MIDDLEWARE_CLASSES` setting. Because middleware order
|
||||
matters, you should follow these guidelines:
|
||||
to your :setting:`MIDDLEWARE` setting. Because middleware order matters, follow
|
||||
these guidelines:
|
||||
|
||||
* Make sure it's one of the first middlewares installed.
|
||||
* It should come after ``SessionMiddleware``, because ``LocaleMiddleware``
|
||||
|
@ -2075,9 +2075,9 @@ matters, you should follow these guidelines:
|
|||
to resolve the requested URL.
|
||||
* If you use ``CacheMiddleware``, put ``LocaleMiddleware`` after it.
|
||||
|
||||
For example, your :setting:`MIDDLEWARE_CLASSES` might look like this::
|
||||
For example, your :setting:`MIDDLEWARE` might look like this::
|
||||
|
||||
MIDDLEWARE_CLASSES = [
|
||||
MIDDLEWARE = [
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue