6

我总是使用这个脚本来编译 django.po 并且它一直在工作:

#!/bin/sh
django-admin.py makemessages -a
django-admin.py compilemessages

突然它停止工作,出现以下错误:

$ i18n.sh
Traceback (most recent call last):
  File "c:/Python34/Scripts/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line
385, in execute_from_command_line
    utility.execute()
  File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line
377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 288,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 338,
 in execute
    output = self.handle(*args, **options)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 533,
 in handle
    return self.handle_noargs(**options)
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 283, in handle_noargs
    potfiles = self.build_potfiles()
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 299, in build_potfiles
    file_list = self.find_files(".")
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 358, in find_files
    ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings
.STATIC_ROOT)]
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 358, in <listcomp>
    ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings
.STATIC_ROOT)]
  File "c:\Python34\lib\ntpath.py", line 491, in normpath
    if path.startswith(special_prefixes):
AttributeError: 'NoneType' object has no attribute 'startswith'
processing file django.po in c:\Users\Debora\workspace\opti\opti2.0\project\loca
le\pt_BR\LC_MESSAGES

有人有什么想法吗?

我不知道这是什么原因造成的。最近我将 django 1.7 更新到 1.7.1,安装了一些不相关的软件包,这就是我记得做的可能会影响的事情。

4

6 回答 6

5

升级到 Django 1.7 后遇到同样的问题

我通过在每次运行时指定设置模块来修复它django-admin.py

cd ~/myproject/myproject # where the ``locale`` folder exists
PYTHONPATH=~/myproject django-admin.py makemessages --settings=myproject.settings -l <language>

更新:这是 Django 1.7.2 中修复的错误,请参阅: https ://docs.djangoproject.com/en/1.7/releases/1.7.2/ https://code.djangoproject.com/ticket/23717

于 2014-11-07T10:21:41.763 回答
3

首先定义makemessages的本地路径

LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale/'),
)

在终端

$python manage.py makemessages -l pl

去文件夹并打开文件编辑.po文件

然后在终端

$python manage.py 编译消息

它在 Django 1.7 中运行良好并且也升级了。

我想它可能会帮助你。

于 2014-11-26T13:31:02.747 回答
2

问题是当你没有设置你的STATIC_ROOTMEDIA_ROOT设置值时。像这样设置后:

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

我正在使用make_messages.sh脚本:

#!/usr/bin/env bash

for dir in `find -maxdepth 1 -type d ! -iname ".*"`; do
    echo $dir
    tmp=$(basename $dir)
    dir="$tmp"
    skip_this=0
    for tmp in static media; do
        if [ "$dir" = "$tmp" ]; then
            skip_this=1
            break
        fi
    done

    if [ "$skip_this" = "1" ]; then
        echo Skipping $dir
        continue
    fi

    cd `dirname $0`/$dir
    if [ ! -d locale ] ; then
        echo Creating 'locale' directory
        mkdir locale
    fi
    ../manage.py makemessages -l pl -l en -l de
        cd ..
done

并在执行后make_messages.sh

./static_page
processing locale pl
processing locale en
processing locale de
./common
Creating locale directory
processing locale pl
processing locale en
processing locale de

这是我的compile_messages.sh脚本:

#!/usr/bin/env bash

for dir in `find -maxdepth 1 -type d ! -iname ".*"`; do
        echo $dir
        tmp=$(basename $dir)
        dir="$tmp"
        skip_this=0
        for tmp in static static_custom media; do
                if [ "$dir" = "$tmp" ]; then
                        skip_this=1
                        break
                fi
        done

        if [ "$skip_this" = "1" ]; then
                echo Skipping $dir
                continue
        fi

        cd `dirname $0`/$dir
        ../manage.py compilemessages -l pl -l en -l de
        cd ..
done
于 2014-11-02T14:10:56.587 回答
2

我在使用 Django 1.7.1 时遇到了同样的问题。

我通过将 command: 更改django-admin.pypython manage.py.

所以我的整个命令是这样的:

python manage.py makemessages --locale=en --ignore=templates/admin --ignore=project/settings.py

于 2014-11-10T19:35:41.840 回答
2

只需STATIC_ROOT在您的 settings.py 文件中设置即可。

这是Django 1.7.1 中的错误,应该在 Django 1.7.2 中删除

(由于Django 1.6.2STATIC_ROOT默认为None, before ''。)

于 2014-12-08T17:09:28.010 回答
0

我有同样的问题。我尝试使用 django-admin 运行,但遇到了这个问题。

当我使用 manage.py 运行它时,它运行正常。

python manage_local.py makemessages -l cs --settings=gprojects.settings_local

使用 manage.py,manage_local.py 是我的备用版本。

于 2014-10-31T15:30:15.603 回答