首页 > 解决方案 > 加载后未应用Django admin css

问题描述

我正在使用 nginx 来提供我的 django 静态文件。在浏览器中我可以看到它们已经加载完毕,base.css、login.css、responsive.css 的状态都是 200,我可以点击它们并查看它们的内容。

问题是它们似乎没有应用在 html 中。html 看起来仍然完全没有应用 css 格式。nginx 日志中没有错误,chrome 中的网络选项卡中也没有错误。我试过 chrome 和 firefox

使用 Django 2.2.4

相关的nginx配置

server {
    listen          8000;
    server_name     127.0.0.1;

    location /static/ {
        autoindex on;
        alias /home/ubuntu/<SECRET_PATH>/static/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/<SECRET_PATH>/dashboard.sock;
    }
}

标签: cssdjango

解决方案


根据您的评论,似乎没有为 CSS 文件返回正确的 mime 类型。在您的 NGINX conf 中,它通常位于/etc/nginx/nginx.conf,请确保您已包含以下 mime:

include "/etc/nginx/mime.types";

在你的 mime 中,确保为 CSS 文件设置了正确的 mime 类型。


推荐阅读