django i18n 切换语言能在runserver下工作,当用apache时就不正常工作 求大神帮助??
html代码如下:
<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代码:
$('.change_language').click(function(e){
e.preventDefault();
$('#language').val($(this).attr('lang_code'));
$('#change_language_form').submit();
return false;
}
);
django settings.py设置如下:
。。。。。。。。。。。。。。。。。
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',
)
。。。。。。。。。。。。。。。。。。。。。。。。。。
djangoz中urls.py设置加入了
url(r'^i18n/', include('django.conf.urls.i18n'))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将带有cache的所有middleware注销掉就行