获取权限错误:[Errno 13]执行操作时权限被拒绝。/manage.py collecstatic

2024-09-27 19:28:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在运行collectstatic命令时得到PermissionError: [Errno 13] Permission denied:

以前我用s3处理静态文件,但我不想用它。我切换回Django的原生静态处理程序。我恢复了设置并删除了STATICFILES_STORAGE。但是现在我开始得到PermissionError

我甚至将static文件夹权限更改为777,但这没有帮助。 我尝试创建一个新项目,但在该项目中,collectstatic命令运行良好。 我还在我的系统上的两个不同位置克隆了同一个项目,但它也不起作用

静态文件夹所有者也是正确的

drwxr-xr-x  6 rohit.chopra domain users 4096 Jul  4 13:24 static/
drwxr-xr-x  2 rohit.chopra domain users 4096 Jul  4 13:22 templates/

Setting.py

# STATICFILES_DIRS = [
#     os.path.join(BASE_DIR, 'static'),
# ]
# STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
# STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

DEFAULT_FILE_STORAGE = 'medicine.storage_backends.MediaStorage'

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Traceback

Type 'yes' to continue, or 'no' to cancel: yes
Copying '/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/contrib/admin/static/admin/img/icon-yes.svg'
2020-07-04 13:51:30,064 - [bugsnag] WARNING - No API key configured, couldn't notify
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/rohit.chopra/virtualenvs/medicine/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/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
    collected = self.collect()
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
    handler(path, prefixed_path, storage)
  File "/home/rohit.chopra/virtualenvs/medicine/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/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/files/storage.py", line 54, in save
    return self._save(name, content)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/files/storage.py", line 317, in _save
    os.makedirs(directory, self.directory_permissions_mode)
  File "/usr/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/rohit.chopra/projects/medicine/static/admin/img'

我已经评论了以前的设置

你们能帮我解决这个问题吗


Tags: djangoinpyselfhomelibpackagesline
1条回答
网友
1楼 · 发布于 2024-09-27 19:28:21

您确定正确设置了路径吗?STATIC_ROOT配置应该指向应用程序/项目结构之外的目录(例如,""/var/www/medicine/static/"),您配置的Web服务器(Apache/Nginx/other)将在那里查找视图中引用的文件。据我所知,您将STATIC_ROOT指向项目中的目录

因此,基本上有三件事需要配置:

  • STATIC_ROOT:外部目录,您希望在其中收集静态文件,并且生产Web服务器应该在其中搜索这些文件。对于开发服务器,您不需要收集静态文件,因为它们直接由django.contrib.staticfiles应用程序提供服务
  • STATIC_URL:使用{% static %}templatetag时将添加到模板中的相对URL
  • 如果希望Django搜索静态文件以收集在project app模块下名为static的目录之外的其他位置,则可以使用STATICFILES_DIRS设置定义这些位置

相关问题 更多 >

    热门问题