首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django :执行命令collectstatic raise UnicodeDecodeError

Django :执行命令collectstatic raise UnicodeDecodeError
EN

Stack Overflow用户
提问于 2012-08-11 22:16:57
回答 2查看 2.5K关注 0票数 1

为什么要提高UnicodeDecodeError?我尝试使用apache来部署我的django应用程序来复制静态文件,输入

代码语言:javascript
复制
$python manage.py collectstatic

我得到了如下的错误信息。

代码语言:javascript
复制
You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
collected = self.collect()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 104, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 137, in list
for path in utils.get_files(storage, ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/utils.py", line 37, in get_files
for fn in get_files(storage, ignore_patterns, dir):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/utils.py", line 37, in get_files
for fn in get_files(storage, ignore_patterns, dir):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/utils.py", line 25, in get_files
directories, files = storage.listdir(location)
File "/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py", line 236, in listdir
if os.path.isdir(os.path.join(path, entry)):
File "/usr/lib/python2.7/posixpath.py", line 71, in join
path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xba in position 1: ordinal not in range(128)

我的静态文件有什么问题?我的settings.py

代码语言:javascript
复制
import os
PROJECT_ROOT = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static/')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'


STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

和apache主机配置

代码语言:javascript
复制
ServerName www.abcd.org
DocumentRoot /srv/www/yyy

<Directory /srv/www/yyy>
    Order allow,deny 
    Allow from all 
</Directory>

WSGIDaemonProcess yyy.djangoserver processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup iii.djangoserver

WSGIScriptAlias / /srv/www/yyy/apache/django.wsgi

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-12 00:03:48

要复制的静态文件的一个或多个路径似乎包含非ASCII字符。

它与目标目录的路径无关。

的一种方法是将放入

代码语言:javascript
复制
try:
    print path
except:
    pass
try:
    print entry
except:
    pass  

在/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py的第236行之前稍等片刻,然后再次运行manage.py。

然后,您应该会看到问题发生在哪里(您不会看到真正的罪魁祸首,但会看到它之前的文件,以及可能是问题文件的目录)。

,或者您也可以使用pdb

代码语言:javascript
复制
python -m pdb manage.py collectstatic

并检查是哪个文件在调试器中导致了问题。

票数 3
EN

Stack Overflow用户

发布于 2016-03-29 16:34:02

当我在docker容器中使用django-pipeline时,我也遇到了同样的错误。事实证明,由于某种原因,系统使用了POSIX语言环境。我使用了这里提出的解决方案,并在system shell中导出了locale设置:

代码语言:javascript
复制
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

之后你可以检查你的语言环境应该是这样的:

代码语言:javascript
复制
vagrant@vagrant-ubuntu-trusty-64:/project$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

它工作得很好。另外,请注意,我在docker和外部机器中都这样做了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11915432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档