css - Django,强制重新加载 css/js,并收集静态
问题描述
假设我已经对我的开发机器上的 css 文件进行了大量更新(我的浏览器设置为忽略缓存,并不总是立即看到更新)。
在这个问题和其他地方,我看到了在链接中添加版本号的方法:
<link type="text/css" href={% static "/path/mystyles.css?version=2" %} rel="stylesheet">
,
这很好,但是在开发机器上,我在控制台中收到错误,并且找不到文件:
GET http://127.0.0.1:8000/path/mystyles.css%3Fversion%3D2 net::ERR_ABORTED 404 (Not Found)
我读过这可能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
?它将从哪里获取文件以覆盖这些文件?
解决方案
最终轻松工作的是更改版本标签的格式:
<link type="text/css" href="{% static '/path/mystyle.css' %}?version=2" rel="stylesheet">
代替:
<link type="text/css" href={% static "/path/mystyles.css?version=2" %} rel="stylesheet">
在开发和生产中都很好。
推荐阅读
- android - 使用 kotlin 的 android 复选框 recyclerview
- javascript - 在页面上强制加载 JS 脚本
- rust - Rust 宏:捕获完全匹配的标记
- javascript - Heroku 无法与后端对话
- sql - 我如何在 Athena 中正确使用 sql 'case when'
- c - 为什么我得到这个程序的分段错误?
- node.js - mongoose 传入的参数必须是 12 字节的单个字符串或 24 个十六进制字符的字符串
- c++ - ADXL355 使用 SPI 和 arduino uno 将数据记录到 sd 卡
- javascript - 合并两个数组时创建唯一数组
- go - 如何将钩子添加到 zap 记录器中?