我正在使用Django 2.2版。当我运行命令
python manage.py collectstatic
我在bash终端上获得以下登录信息。
You have requested to collect static files at the destination
location as specified in your settings:
/home/djapp/poorface/staticfiles
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 15, in <module>
execute_from_command_line(sys.argv)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
collected = self.collect()
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 353, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/files/storage.py", line 49, in save
return self._save(name, content)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/files/storage.py", line 288, in _save
os.chmod(full_path, self.file_permissions_mode)
TypeError: an integer is required (got type str)
我将静态文件的权限更改为-rwxrwxrwx。这样输出也没有变化。
manage.py看起来像
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Poorface.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
答案 0 :(得分:0)
这是骇客-并非正确的解决方法!
我在OSX和Ubuntu上都遇到了这个问题。似乎某些软件包以文件许可权作为字符串结尾,而大多数是整数。
我入侵了django,以解决此问题,并确定了导致问题的软件包-django-filebrowser-最好不要入侵django,但如果在此不顾一切的话,请更改core / files / storage.py第289行::
if self.file_permissions_mode is not None:
if type(self.file_permissions_mode) == type("duck"):
print(full_path, self.file_permissions_mode, type(self.file_permissions_mode))
self.file_permissions_mode = int(self.file_permissions_mode)
os.chmod(full_path, self.file_permissions_mode)
此报告:
/home/django/teamup/shared_static/filebrowser/css/filebrowser.css 0644 <class 'str'>
我尝试在virtualenv中更改filebrowser的文件权限并重新运行,但这不能解决问题,因此我放弃了。
答案 1 :(得分:0)
是的,这个问题很老了,但我现在又遇到了这个问题,并在几缕白发、篡改各种文件访问权限和一个简单的调试运行后找到了错误源和正确的修复“ manage.py collectstatic":
在过去或者在某些不同的情况下(不记得这是如何进入我的项目开发设置的 - 在我的生产设置中它是正确的)设置“FILE_UPLOAD_PERMISSIONS”是/很好settings.py 像这样:
FILE_UPLOAD_PERMISSIONS = "0644"
根据文档,至少从 Django 1.8 开始,正确设置 是:
FILE_UPLOAD_PERMISSIONS = 0o644
在我知道解决方案的原因后,我还发现了一些提示,即“现在使用 python 3 ......八进制......等等”。但与这个令人沮丧的模糊错误消息没有联系:
… os.chmod(full_path, self.file_permissions_mode)
TypeError: an integer is required (got type str)
在我使用“allways™”(我知道)的命令 python manage.py collectstatic
之后。
所以我希望你不要因为像我这样的一些略显陈旧的项目而白发苍苍!