manage.py collectstatic在macOS 10.13.1中不起作用

时间:2018-01-20 20:04:14

标签: django collectstatic

我在macOS中运行collectstatic时遇到问题。错误是OSError:[Errno 45]不支持操作:' / home / juan'

./manage.py collectstatic     
Copying '/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/admin/static/admin/css/widgets.css'
Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 189, in handle
    collected = self.collect()
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
    handler(path, prefixed_path, storage)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
    self.storage.save(prefixed_path, source_file)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/files/storage.py", line 49, in save
    return self._save(name, content)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/files/storage.py", line 236, in _save
    os.makedirs(directory)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 210, in makedirs
    makedirs(head, mode, exist_ok)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 210, in makedirs
    makedirs(head, mode, exist_ok)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 210, in makedirs
    makedirs(head, mode, exist_ok)
  File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
OSError: [Errno 45] Operation not supported: '/home/juan'

----------

同一项目中的同一命令在ubuntu

中正常运行

1 个答案:

答案 0 :(得分:0)

关于有这个问题的人。您需要正确设置静态媒体根目录和URL。这是一个示例:

settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

urls.py:

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)