gpt4 book ai didi

python - Django 操作系统错误 : [Errno 13] Permission denied

转载 作者:太空狗 更新时间:2023-10-29 12:10:35 26 4
gpt4 key购买 nike

我是 python 和 Linux 的新手,如有任何混淆,请提前致歉。我正在尝试使用

收集我的静态文件
python manage.py collectstatic

但是这里有一些错误是我的回溯

> Copying '/var/www/Django/myweb/static/images/test.jpg'
Traceback (most recent call last):
File "manage.py", line 22, in <module>
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'

我也试试 sudo python manage.py collectstatic

>File "manage.py", line 17, in <module>
"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

STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = '/var/www/staticfiles'

最佳答案

给文件夹/var/www/staticfiles必要的权限:

chmod -R 755 /var/www/staticfiles

如评论中所述,不建议向所有用户授予 777 权限,而是尝试使用 chown -R your_user your_file 更改文件夹的所有者

>

关于python - Django 操作系统错误 : [Errno 13] Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45907648/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com