Fixed #24124 -- Changed context_processors in the default settings.py

This commit is contained in:
Collin Anderson 2015-01-12 10:48:49 -05:00
parent bbbed99f62
commit 26a92619f6
6 changed files with 39 additions and 53 deletions

View File

@ -61,10 +61,7 @@ TEMPLATES = [
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
'django.template.context_processors.debug', 'django.template.context_processors.debug',
'django.template.context_processors.i18n', 'django.template.context_processors.request',
'django.template.context_processors.tz',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
], ],

View File

@ -501,10 +501,7 @@ Open your settings file (:file:`mysite/settings.py`, remember) and add a
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
'django.template.context_processors.debug', 'django.template.context_processors.debug',
'django.template.context_processors.i18n', 'django.template.context_processors.request',
'django.template.context_processors.tz',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
], ],

View File

@ -1873,10 +1873,9 @@ for :doc:`managing stored files </topics/files>`. It must end in a slash if set
to a non-empty value. You will need to :ref:`configure these files to be served to a non-empty value. You will need to :ref:`configure these files to be served
<serving-uploaded-files-in-development>` in both development and production. <serving-uploaded-files-in-development>` in both development and production.
In order to use ``{{ MEDIA_URL }}`` in your templates, you must have If you want to use ``{{ MEDIA_URL }}`` in your templates, add
``'django.template.context_processors.media'`` in the ``'context_processors'`` ``'django.template.context_processors.media'`` in the ``'context_processors'``
option of :setting:`TEMPLATES`. It's there by default, but be sure to include option of :setting:`TEMPLATES`.
it if you override that setting and want this behavior.
Example: ``"http://media.example.com/"`` Example: ``"http://media.example.com/"``

View File

@ -554,12 +554,9 @@ settings file, the default template engine contains the following context
processors:: processors::
[ [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug', 'django.template.context_processors.debug',
'django.template.context_processors.i18n', 'django.template.context_processors.request',
'django.template.context_processors.media', 'django.contrib.auth.context_processors.auth',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
] ]
@ -625,7 +622,7 @@ Built-in template context processors
Context processors Context processors
------------------ ------------------
Here's what each of the default processors does: Here's what each of the built-in processors does:
django.contrib.auth.context_processors.auth django.contrib.auth.context_processors.auth
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -695,8 +692,7 @@ django.template.context_processors.request
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If this processor is enabled, every ``RequestContext`` will contain a variable If this processor is enabled, every ``RequestContext`` will contain a variable
``request``, which is the current :class:`~django.http.HttpRequest`. Note that ``request``, which is the current :class:`~django.http.HttpRequest`.
this processor is not enabled by default; you'll have to activate it.
django.contrib.messages.context_processors.messages django.contrib.messages.context_processors.messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -208,6 +208,7 @@ Include a form in ``template.html`` that will ``POST`` to this view:
.. code-block:: html+django .. code-block:: html+django
{% load tz %} {% load tz %}
{% get_current_timezone as TIME_ZONE %}
<form action="{% url 'set_timezone' %}" method="POST"> <form action="{% url 'set_timezone' %}" method="POST">
{% csrf_token %} {% csrf_token %}
<label for="timezone">Time zone:</label> <label for="timezone">Time zone:</label>
@ -311,16 +312,15 @@ time zone is unset, the default time zone applies.
get_current_timezone get_current_timezone
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
When the ``django.template.context_processors.tz`` context processor is You can get the name of the current time zone using the
enabled -- by default, it is -- each :class:`~django.template.RequestContext` ``get_current_timezone`` tag::
contains a ``TIME_ZONE`` variable that provides the name of the current time
zone.
If you don't use a :class:`~django.template.RequestContext`, you can obtain
this value with the ``get_current_timezone`` tag::
{% get_current_timezone as TIME_ZONE %} {% get_current_timezone as TIME_ZONE %}
If you enable the ``django.template.context_processors.tz`` context processor,
each :class:`~django.template.RequestContext` will contain a ``TIME_ZONE``
variable with the value of ``get_current_timezone()``.
Template filters Template filters
---------------- ----------------

View File

@ -28,8 +28,6 @@ bit of i18n-related overhead in certain places of the framework. If you don't
use internationalization, you should take the two seconds to set use internationalization, you should take the two seconds to set
:setting:`USE_I18N = False <USE_I18N>` in your settings file. Then Django will :setting:`USE_I18N = False <USE_I18N>` in your settings file. Then Django will
make some optimizations so as not to load the internationalization machinery. make some optimizations so as not to load the internationalization machinery.
You'll probably also want to remove ``'django.template.context_processors.i18n'``
from the ``'context_processors'`` option of your :setting:`TEMPLATES` setting.
.. note:: .. note::
@ -812,28 +810,29 @@ the second will always be in English.
Other tags Other tags
---------- ----------
Each ``RequestContext`` has access to three translation-specific variables:
* ``LANGUAGES`` is a list of tuples in which the first element is the
:term:`language code` and the second is the language name (translated into
the currently active locale).
* ``LANGUAGE_CODE`` is the current user's preferred language, as a string.
Example: ``en-us``. (See :ref:`how-django-discovers-language-preference`.)
* ``LANGUAGE_BIDI`` is the current locale's direction. If True, it's a
right-to-left language, e.g.: Hebrew, Arabic. If False it's a
left-to-right language, e.g.: English, French, German etc.
If you don't use the ``RequestContext`` extension, you can get those values with
three tags::
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_current_language_bidi as LANGUAGE_BIDI %}
These tags also require a ``{% load i18n %}``. These tags also require a ``{% load i18n %}``.
* ``{% get_available_languages as LANGUAGES %}`` returns a list of tuples in
which the first element is the :term:`language code` and the second is the
language name (translated into the currently active locale).
* ``{% get_current_language as LANGUAGE_CODE %}`` returns the current user's
preferred language, as a string. Example: ``en-us``. (See
:ref:`how-django-discovers-language-preference`.)
* ``{% get_current_language_bidi as LANGUAGE_BIDI %}`` returns the current
locale's direction. If True, it's a right-to-left language, e.g.: Hebrew,
Arabic. If False it's a left-to-right language, e.g.: English, French, German
etc.
If you enable the ``django.template.context_processors.i18n`` context processor
then each ``RequestContext`` will have access to ``LANGUAGES``,
``LANGUAGE_CODE``, and ``LANGUAGE_BIDI`` as defined above.
.. versionchanged:: 1.8
The ``i18n`` context processor is not enabled by default for new projects.
You can also retrieve information about any of the available languages using You can also retrieve information about any of the available languages using
provided template tags and filters. To get information about a single language, provided template tags and filters. To get information about a single language,
use the ``{% get_language_info %}`` tag:: use the ``{% get_language_info %}`` tag::
@ -1506,11 +1505,6 @@ As a convenience, Django comes with a view, :func:`django.views.i18n.set_languag
that sets a user's language preference and redirects to a given URL or, by default, that sets a user's language preference and redirects to a given URL or, by default,
back to the previous page. back to the previous page.
Make sure that the following context processor is enabled in the
:setting:`TEMPLATES` setting in your settings file::
'django.template.context_processors.i18n'
Activate this view by adding the following line to your URLconf:: Activate this view by adding the following line to your URLconf::
url(r'^i18n/', include('django.conf.urls.i18n')), url(r'^i18n/', include('django.conf.urls.i18n')),
@ -1542,10 +1536,13 @@ Here's example HTML template code:
.. code-block:: html+django .. code-block:: html+django
{% load i18n %}
<form action="{% url 'set_language' %}" method="post"> <form action="{% url 'set_language' %}" method="post">
{% csrf_token %} {% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" /> <input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language"> <select name="language">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %} {% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %} {% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}> <option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>