我总是使用这个脚本编译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,安装了一些无关的软件包,这是我记得做的可能会受到影响的。
答案 0 :(得分: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
答案 1 :(得分:3)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale/'),
)
在终端
$ python manage.py makemessages -l pl
转到文件夹并打开文件编辑.po文件
然后在终端
$ python manage.py compilemessages
它在Django 1.7中运行良好,也升级了。
我认为它可能对你有所帮助。
答案 2 :(得分:2)
问题在于您未设置STATIC_ROOT
和MEDIA_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
答案 3 :(得分:2)
使用Django 1.7.1时遇到了同样的问题。
我通过将命令django-admin.py
更改为python manage.py
来修复它。
所以我的整个命令都是这样的:
python manage.py makemessages --locale=en --ignore=templates/admin --ignore=project/settings.py
答案 4 :(得分:2)
只需在settings.py文件中设置STATIC_ROOT
。
这是bug in Django 1.7.1,应该在Django 1.7.2中删除
(由于Django 1.6.2 STATIC_ROOT
在None
之前默认为''
。)
答案 5 :(得分:0)
我有同样的问题。我试着用django-admin运行,并且遇到了这个问题。
当我使用manage.py运行它时,它运行正常。
python manage_local.py makemessages -l cs --settings=gprojects.settings_local
使用manage.py,manage_local.py是我的替代版本。