django 18n:makemessages不会创建.po文件

时间:2014-12-01 05:47:37

标签: python django

我有一个django项目 在这个项目中,有一个名为core

的应用程序

cd core并尝试python ../manage.py makemessages -l tw

但它没有创建django.po文件,
我也尝试django-admin.py makemessages -l tw,但有错误:

    Traceback (most recent call last):
File "/Users/winsome/env/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/commands/makemessages.py", line 283, in handle_noargs
potfiles = self.build_potfiles()
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/commands/makemessages.py", line 299, in build_potfiles
file_list = self.find_files(".")
File "/Users/winsome/env/lib/python2.7/site-packages/django/core/management/commands/makemessages.py", line 358, in find_files
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
File "/Users/winsome/env/lib/python2.7/posixpath.py", line 327, in normpath
initial_slashes = path.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith' 

请帮助我,谢谢

settings.py

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',  )

LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True

LOCALE_PATHS = ( os.path.join(BASE_DIR, 'locale'), )
ugettext = lambda s: s
LANGUAGES = (
    ('en', ugettext('English')),
    ('tw', ugettext('Chinese')), )

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.i18n",)
    STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
    ("js", os.path.join(STATIC_ROOT,'js')),
    ("css", os.path.join(STATIC_ROOT,'css')),
    ("img", os.path.join(STATIC_ROOT,'img')),
    ("video", os.path.join(STATIC_ROOT,'video')),
    ("file", os.path.join(STATIC_ROOT,'file')),
    # ("fonts", os.path.join(STATIC_ROOT,'fonts')),
)

模板/英语/ index.html中

{% extends 'global/base.html' %}
{% load i18n %}

<ul id="header">
    <li data-menuanchor="firstPage"><a href="{% url 'core:maininfo' %}#firstPage">{% trans "About" %}</a>
    </li>
    <li data-menuanchor="secondPage"><a href="{% url 'core:maininfo' %}#secondPage">{% trans "Features" %}</a>
    </li>
    <li data-menuanchor="3rdPage"><a href="{% url 'core:maininfo' %}#3rdPage">{% trans "Press" %}</a>
    </li>
</ul>

1 个答案:

答案 0 :(得分:0)

你的问题与已经修复的Django 1.7中的a bug有关。如果您使用git下载了Django,则可以执行git pull。如果不是通过克隆开发版本或使用较旧的稳定Django版本来重新安装Django。