Django OSError: [Errno 13] Permission denied
我是python和Linux的新手,并提前为任何困惑道歉。
我正在尝试使用收集我的静态文件
1 | python manage.py collectstatic |
但这里的错误是我的追溯
Copying '/var/www/Django/myweb/static/images/test.jpg'
Traceback (most recent call last):
File"manage.py", line 22, in
execute_from_command_line(sys.argv)
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/core/management/init.py", line 363, in execute_from_command_line
utility.execute()
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/core/management/init.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
collected = self.collect()
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 364, in copy_file
self.storage.save(prefixed_path, source_file)
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/core/files/storage.py", line 54, in save
return self._save(name, content)
File"/home/test01/Django/VENV/local/lib/python2.7/site-packages/django/core/files/storage.py", line 321, in _save
os.makedirs(directory)
File"/home/test01/Django/VENV/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/var/www/staticfiles/images'
我也尝试
File"manage.py", line 17, in
"Couldn't import Django. Are you sure it's installed and"
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?
这是我的setting.py
1 2 3 4 5 6 | STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ] STATIC_ROOT = '/var/www/staticfiles' |
您可以简单地添加目录的完整路径,而不是更改权限,例如:
1 | STATIC_ROOT = os.path.join(BASE_DIR,"/var/www/staticfiles/") |
资源
授予文件夹/ var / www / staticfiles所需的权限:
1 | chmod -R 755 /var/www/staticfiles |
如评论中所述,不建议向所有用户授予权限