search

Home  >  Q&A  >  body text

Django i18n can work under runserver when switching languages, but it does not work properly when using apache. Can anyone help? ?

html code is as follows:

<form action="/i18n/setlang/" method="post" id="change_language_form">
{% csrf_token %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
    <td>
    <a  href="#" lang_code="{{ language.code }}" class="change_language">
        {% if language.code == "zh-cn" %}
        简体
        {% else %}
        Eng
        {% endif %}
    </a>
    </td>
 {% endfor %}
<input type="hidden" value="" name="language" id="language" />
</form>
</form>

js code:

$('.change_language').click(function(e){
           e.preventDefault();
           $('#language').val($(this).attr('lang_code'));
           $('#change_language_form').submit();
           return false;
       }
   );

django settings.py settings are as follows:

. . . . . . . . . . . . . . . . .

USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.

USE_L10N = True
ugettext = lambda s: s

LANGUAGES = (
    ('zh-cn', ugettext('Chinese')),
    ('en', ugettext('English')),
)

MIDDLEWARE_CLASSES = (
    'middleware.createuserinfo.CreateUserInfoMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'pagination.middleware.PaginationMiddleware',
    'django_authopenid.middleware.OpenIDMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'django.middleware.transaction.TransactionMiddleware',
    'djangobb_forum.middleware.LastLoginMiddleware',
    'djangobb_forum.middleware.UsersOnline',
)

. . . . . . . . . . . . . . . . . . . . . . . . . .

The urls.py setting in djangoz has been added

url(r'^i18n/', include('django.conf.urls.i18n'))
过去多啦不再A梦过去多啦不再A梦2754 days ago447

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 17:06:21

    Just log out all middleware with cache

    reply
    0
  • Cancelreply