Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django、强制重新加载css/js和collectstatic_Css_Django_Static Files - Fatal编程技术网

Django、强制重新加载css/js和collectstatic

Django、强制重新加载css/js和collectstatic,css,django,static-files,Css,Django,Static Files,假设我已经在我的开发机器上对css文件进行了一次很好的更新(我的浏览器设置为忽略缓存,不总是立即看到更新) 在和其他地方,我看到了向链接添加版本号的方法: 这很好,但是在dev机器上,我在控制台中遇到一个错误,并且找不到该文件: GEThttp://127.0.0.1:8000/path/mystyles.css%3Fversion%3D2 net::ERR_中止404(未找到) 我已经读到可能collectstatic会在开发端修复它,但是有一个看起来不祥的警告: You have requ

假设我已经在我的开发机器上对css文件进行了一次很好的更新(我的浏览器设置为忽略缓存,不总是立即看到更新)

在和其他地方,我看到了向链接添加版本号的方法:

这很好,但是在dev机器上,我在控制台中遇到一个错误,并且找不到该文件:

GEThttp://127.0.0.1:8000/path/mystyles.css%3Fversion%3D2 net::ERR_中止404(未找到)

我已经读到可能
collectstatic
会在开发端修复它,但是有一个看起来不祥的警告:

You have requested to collect static files at the destination
location as specified in your settings:

    /patttthhhhh/static

This will overwrite existing files!
Are you sure you want to do this?

运行
collectstatic
时会发生什么?它将从何处获取文件以覆盖这些文件

推荐的方法是使用类似django compressor()或类似的工具将CSS处理成单个文件,然后在文件名或目录中烘焙一个哈希。这样,您的资产就变成了
/mystyles.beb23fe.css

最终很容易工作的是更改版本标记的格式:

而不是:

在开发和生产方面表现良好