为什么 gunicorn 找不到静态文件?

Why gunicorn cannot find static files?

运行 Django 开发服务器没有问题:'python manage.py runserver 9000' 但是如果使用 gunicorn,它会抱怨:

'http://innovindex.com/pubmed/static/js/jquery-3.2.1.min.js'

为什么 gunicorn 找不到本地 jquery 但 Django 可以?

设置为:

settings.py(好像不相关):

STATIC_URL = '/pubmed/static/'

在“/etc/nginx/sites-enabled/django”中

location /static {
   alias /home/django/innovindex/pubmed/static/;
}

我的应用程序如下所示:

/home/django/innovindex

是 'manage.py' 所在的位置。

非常感谢!!!

根据 Django 文档中的 Deploying static files,除了设置 STATIC_ROOT 设置外,您还必须 运行 collectstatic 命令。

首先确保您 STATIC_ROOT 设置为与您的 nginx 配置相匹配的正确路径:

STATIC_ROOT = '/home/django/innovindex/pubmed/static/'

注意这是绝对路径。

然后运行:

python manage.py collectstatic

在你的项目目录中。

这会将您所有的静态文件复制到 /home/django/innovindex/pubmed/static/