gpt4 book ai didi

python - Django Gunicorn 不加载静态文件

转载 作者:太空狗 更新时间:2023-10-29 18:24:28 28 4
gpt4 key购买 nike

我正在尝试使用 gunicorn 和 nginx 部署我的 django 元素,但我需要一些帮助。当我编写 gunicorn myproject.wsgi:application 时,我设法在本地主机页面中看到我的网站,但没有任何 css。为什么 gunicorn 不加载我的 css 文件到我的元素的静态文件夹中?

Guinicorn_start 脚本:https://dpaste.de/TAc4Gunicorn 输出:https://dpaste.de/C6YX

最佳答案

Gunicorn 只会提供动态内容,即 Django 文件。所以你需要设置一个代理服务器,比如 nginx 来处理静态内容(你的 CSS 文件)。我假设您以正确的方式启动 Gunicorn,所以您只需要配置 nginx 来提供静态文件。您可以使用如下配置,您只需更改静态文件的路径即可:

server {
listen 80;
server_name localhost;

location / {
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8000;
}
location /static {
autoindex on;
alias /path/to/staticfiles;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

即使设置了此配置,您也必须调用“./manage.py collectstatic”才能使您的 css 正常工作

关于python - Django Gunicorn 不加载静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20175243/

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