css - 加载后未应用 Django admin css

标签 css django

我正在使用 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;
    }
}

最佳答案

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

包含“/etc/nginx/mime.types”;

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

关于css - 加载后未应用 Django admin css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57488712/

相关文章:

css - react CSS过渡组动画单个元素

python - Django 模板条件检查

python - 如何从django中具有外键关系的两个模型中选择值

python - 将 CKEditor 添加到 Django 项目

html - 为什么设置 p 元素的背景颜色也会设置上图的背景颜色

css - 伪元素上的渐变

javascript - 将显示从 block 更改为无,然后淡入

javascript - anchor 覆盖并且没有正确改变颜色,因为不能完全点击

Python setup.py 安装抛出 zipimport.ZipImportError

python - 在 Heroku 上使用 Django 将大文件上传到 AWS S3 Bucket 没有 30 秒的请求超时