我正在尝试在PythonAnywhere的Bash终端中使用collectstatic
命令:
python manage.py collectstatic
但我得到:
PermissionError: [Errno 13] 拒绝访问:'/static'
请问有人可以帮忙吗?我已经试了两天了还是无法解决。
这是完整的错误信息:
复制'/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/contrib/admin/static/admin/img/inline-delete.svg'时发生错误。
Traceback (most recent call last):
File "manage.py", line 22, in execute_from_command_line(sys.argv)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute()
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, cmd_options)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, options)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle collected = self.collect()
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect handler(path, prefixed_path, storage)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 364, in copy_file self.storage.save(prefixed_path, source_file)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/core/files/storage.py", line 54, in save return self._save(name, content)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/site-packages/django/core/files/storage.py", line 321, in _save os.makedirs(directory)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/os.py", line 210, in makedirs makedirs(head, mode, exist_ok)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/os.py", line 210, in makedirs makedirs(head, mode, exist_ok)
File "/home/DMells123/.virtualenvs/nomadpad-virtualenv/lib/python3.6/os.py", line 220, in makedirs mkdir(name, mode) PermissionError: [Errno 13] Permission denied: '/static'
静态设置
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR, 'posts/media')
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'
/static
)了 - 大多数操作系统不会允许你在那里创建一个目录,除非你拥有特权。将它设置为你拥有写入权限的路径...(也许你只是不想要那个/
在那里) - Jon Clements