简体   繁体   English

找不到 static 文件。 我收到未设置“STATIC_ROOT”的错误

[英]Cannot locate a static file. I get an error that 'STATIC_ROOT' is not set

What I want to do我想做的事

I'm trying to deploy my Django app using AWS (EC2), nginx, and gunicorn.我正在尝试使用 AWS (EC2)、nginx 和 gunicorn 部署我的 Django 应用程序。 The current goal is to place the static files in the directory /usr/share/nginx/html/static.当前目标是将 static 文件放在目录 /usr/share/nginx/html/static 中。

Problem that is occurring正在发生的问题

I created /usr/share/nginx/html/static and then ran python manage.py collectstatic command.我创建了 /usr/share/nginx/html/static 然后运行python manage.py collectstatic命令。

I had set STATIC_ROOT in settings.py to STATIC_ROOT='/usr/share/nginx/html/static' before, so I thought I could use the collectstatic command to collect static files from within the Django project and place them in /usr/share/nginx/html/static.我之前在 settings.py 中将 STATIC_ROOT 设置为 STATIC_ROOT='/usr/share/nginx/html/static',所以我想我可以使用 collectstatic 命令从 Django 项目中收集 static 文件并将它们放在 /usr/共享/nginx/html/静态。 However, that wasn't the case.然而,事实并非如此。 Instead I got an error saying django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.相反,我收到一条错误消息, django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. Could you please explain why this is so?你能解释一下为什么会这样吗?

I have tried some suggested solutions over the internet but the problem still exists.我已经通过互联网尝试了一些建议的解决方案,但问题仍然存在。 I'd be really appreciated if you could reply to me.如果您能回复我,我将不胜感激。

error message错误信息

'STATIC_ROOT' 'STATIC_ROOT'

I tried created a Django project and define STATIC_ROOT='/usr/share/nginx/html/static我尝试创建了一个 Django 项目并定义 STATIC_ROOT='/usr/share/nginx/html/static

The only problem I face is我面临的唯一问题是

PermissionError: [Errno 13] Permission denied: '/usr/share/nginx/html/static/admin'

After fixing permission it worked.修复许可后,它起作用了。

So As is see you are running collectstatic with a specific setting file( private_diary.settings ) make sure static root is defined in that file.因此,正如所见,您正在使用特定设置文件( private_diary.settings )运行 collectstatic ,确保在该文件中定义 static 根。

Make sure you have permission in the static directory确保您在 static 目录中具有权限

And make sure to include STATIC_ROOT in your settings.py并确保在您的 settings.py 中包含 STATIC_ROOT

STATIC_ROOT = "/usr/share/nginx/html/static"

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    "/usr/share/nginx/html/static"
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM