0

我是 django 网络应用程序的新手,

我的项目结构如下:x ->x ->settings.py

在 settings.py 我有以下条目:

from django.utils.translation import ugettext_lazy as _
LOCALE_PATHS = ( 
join (BASE_DIR, 'locale'), 
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.locale.LocaleMiddleware',
)

LANGUAGE_CODE = 'en-us'
LANGUAGES = (
    ('en', _('English')),
    #('en-us', ugettext('English US')),
    ('es', _('Spanish')),
    ('en-Gb', _('English UK')),
)

USE_I18N = True

USE_L10N = True

USE_TZ = True

我已经在我的 MAC OSX 10.7.5 上安装了 get text

在我的模板中:

{% load i18n %}
{% trans "Login To UI Mirror" %}

使用以下命令

django-admin.py makemessages -a

似乎它能够产生django.po

但它缺少

模板中定义的消息 ID。

这是它所拥有的:

#: settings.py:156
msgid "English"
msgstr ""

#: settings.py:158
msgid "Spanish"
msgstr ""

#: settings.py:159
msgid "English UK"
msgstr ""

任何帮助将不胜感激。

谢谢

模板代码:

_base.html:

{% load compress %}
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        {# Mobile meta tag #}
        <meta name="HandheldFriendly" content="True">
        <meta name="MobileOptimized" content="320">
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
        <meta http-equiv="cleartype" content="on">
        {# Favicons #}
        <link rel="icon" href="{{static}}images/uimirror.ico" type="image/x-icon">
        {% block title %}
            {% include "core/_title.html" with location='lgn_reg' %}
        {% endblock title %}

        {# Tile icon for Win8 (144x144 + tile color) #}
        {% block css_media %}
            {% include "core/_media.html" with location='lgn_reg' %}
        {% endblock css_media %}
    </head>

    <body>
        {% block content %}

        {% endblock content %}

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
        {% block script_media %}
            {% include "core/_script_media.html" with location='lgn' %}
        {% endblock script_media %}

    </body>
</html>

第一次扩展:

login_register.html

{% extends 'core/_base.html' %}

{% block css_media %}
    {% include "core/_media.html" with location=location %}
{% endblock css_media %}

{% block content %}
    <div class="uimmaincontainer" id="uimmaincontainer">
    {% include "core/login_register/_login_register_theme.html" with location=location %}
    {% include "core/login_register/_login.html" with location=location%}
    {% include "core/login_register/_register.html" with location=location%}
    </div>
{% endblock content %}

反式块:

_login_register_theme.html

{% load i18n %}
<div class="pt15 {% if location == 'lgn' %} active {% else %} hidden {% endif %}" id="_ui_lgn_them">
    <h4 aria-hidden="true" class="">
        <img width="15" height="15" alt=""
            src="#"
            class="uiHeaderImage img">{% trans "Login To UI Mirror" %}
    </h4>
    <div class="clearfix">
        <div class="mb5 uiHeaderSubTitle f-left fsm tc-3">Enter to the most existing virtual world.</div>
    </div>
</div>
4

1 回答 1

1

我认为您的模板目录结构有问题。Django 模板加载器正在您的应用程序中寻找一个名为“模板”的目录。

您的模板位于 下core/login_register/,因此 django 找不到它们。

您可以为您的模板使用以下结构:

└── yourapp
    └── templates
        └── yourapp 
            ├── base.html
            └── index.html

这样,django 将找到您的模板,您甚至可以在其他应用程序中覆盖这些模板:

└── yourapp
    └── templates
        └── yourapp 
            ├── base.html
            └── index.html
└── anotherapp
    └── templates
        └── yourapp 
            ├── base.html # it will override the template yourapp/templates/yourapp/base.html

这是django 项目的常见结构

于 2014-01-29T18:47:16.440 回答