Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django翻译不起作用?_Django - Fatal编程技术网

Django翻译不起作用?

Django翻译不起作用?,django,Django,我想将我的网站翻译成其他语言,我已经按原样配置了我的设置.py,但没有发生任何更改 我已经创建了消息,我可以在本地文件夹中看到它们,并且我已经成功地编译了它们,没有任何EROR 以下是我的设置: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.

我想将我的网站翻译成其他语言,我已经按原样配置了我的设置.py,但没有发生任何更改

我已经创建了消息,我可以在本地文件夹中看到它们,并且我已经成功地编译了它们,没有任何EROR

以下是我的设置:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # My apps
    'main',

    # Third part apps
    'captcha',
    'jsonify'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

LOCAL_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

LANGUAGE_CODE = 'en'

LANGUAGES = (
    ('ru', _(u'RU')),
    ('en', _(u'EN'))
)
我的看法:

from django.utils.translation import gettext as _

def main(request):
    context = {
        'title':_('Главная'),
    }
    return render(request, 'index.html', context)
此外,我还将上面的
i18n
加载到我的模板中,在那里进行翻译index.html

{% load static %}
{% load i18n %}
<title>{% block head_title %}{{title}}{% endblock %}</title>
{%load static%}
{%load i18n%}
{%block head_title%}{{title}{%endblock%}

我让它开始工作,而不是键入
区域设置路径
我键入了
本地路径
,现在一切正常。

似乎您的默认语言是英语,但您提供了俄语字符串作为默认值-因此,如果您以英语显示页面,则没有理由运行翻译。不过我不确定。@Frax,谢谢你的关注。不,这个网站是俄语的,事实上,我已经为英语而不是俄语生成了地区设置,整个网站都是俄语的。有什么建议吗??