【发布时间】:2019-08-27 12:29:48
【问题描述】:
我正在使用 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)
【问题讨论】:
-
当你运行
ls -al /home时,shell 对权限有何看法?它可能与特定于平台的某些东西有关......例如OSX 具有扩展的权限属性。路径/home/djapp和/home/amit看起来有点粗略......您确定要将静态数据发送到不同的“主”目录吗? -
ls -al /home drwxr-xr-x 8 amit amit 4096 3 月 13 日 15:29 amit drwxr-xr-x 5 djapp djapp 4096 3 月 13 日 17:23 djapp
-
如果它有效,那么将静态数据发送到不同的“主”目录没有问题。
-
您可以尝试使用
--dry-run标志运行,以便查看引用的文件路径。然后,您可以检查给定文件夹的权限。您也可以尝试将 STATIC_ROOT 设置为可以非常确定可以访问的位置...例如/tmp位于文件系统的根目录。 -
--dry-runflag 帮助我解决了问题。但是,我仍然不明白为什么会发生此错误。我正在传递yes参数,这是要传递的参数之一,对文件和文件夹的权限也很好。