简体   繁体   English

Django 中的 Static css 工作不稳定

[英]Static css in Django works unstable

I have css with following content in ecommerce/ecommerce/static/css folder:我有 css 在 ecommerce/ecommerce/static/css 文件夹中有以下内容:

body {background: #68951c;}
h1 {color: #000000;}

When I want to change the color of the background, it changes in PyCharm, but it doesn't change on the web page even when I change the color in BOTH 1) e-commerce/static/css and 2) e-commerce/static/css manually.当我想更改背景颜色时,它会在 PyCharm 中发生变化,但即使我在 1)电子商务/静态/css 和 2)电子商务/手动静态/css。 Even though command "python manage.py collectstatic" had run and the server had re-run it is needlessly.即使命令“python manage.py collectstatic”已经运行并且服务器已经重新运行它是不必要的。 Only one effect - when I ctrl+X following string in html page:只有一种效果 - 当我在 html 页面中按 ctrl+X 跟随字符串时:

  <link rel="stylesheet" type="text/css" href="{% static 'css/base.css' %}">

then the background evaporates.然后背景蒸发。 And when I insert the upper markup and refresh the page, it appears again当我插入上部标记并刷新页面时,它再次出现

(upper markup contained in, in it is not working for some reason) (包含在上面的标记,由于某种原因它不起作用)

项目文件夹

I am guessing this simply is a caching problem.我猜这只是一个缓存问题。 Try to hard reload your browser each time(or just have dev tools open)每次都尝试重新加载浏览器(或者只打开开发工具)

Unless you have some more elaborate front-end build process (eg gulp, webpack etc.) In that case, you should rebuild or watch for file changes除非您有更精细的前端构建过程(例如 gulp、webpack 等)在这种情况下,您应该重建或注意文件更改

If a lot of css files, and then you write css to a new file and you want to go back to the previous file, you have to change the file name to make it work, for example first_file.css second_file.css if you want to go back to first_file.css you have to rename first_file. If a lot of css files, and then you write css to a new file and you want to go back to the previous file, you have to change the file name to make it work, for example first_file.css second_file.css if you want到 go 回到 first_file.css 你必须重命名 first_file。 css becomes first_file_rename.css like this and then it works, I don't know what the problem is, I just got the easy alternative css 变成 first_file_rename.css 像这样然后它工作,我不知道问题是什么,我只是得到了简单的替代方案

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

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