我对Django很新。我启动了一个应用程序,制作了模板和静态目录,将它们添加到项目设置中,然后按照this tutorial运行服务器。然后我想改变我的CSS文件中的一些设置,所以我修改了一些行。但当我再次运行python manage.py runserver
(我在Windows上运行)时,更改没有生效。 CSS的初始代码是:
body {
position: relative;
padding-bottom: 10px;
min-height: 100%;
background: #f7f7f7;
}
我更改了这样的填充:
body {
position: relative;
padding-bottom: 50px;
min-height: 100%;
background: #f7f7f7;
}
当我再次运行django服务器时,新代码没有生效。我用Chrome Dev Tools检查了代码,发现填充值仍然是10px。我一次又一次地运行服务器,但没有任何变化。设置中是否有我遗漏的东西?
答案 0 :(得分:2)
我经常遇到同样的问题,你应该删除staticfiles目录。 此外,您应该在模板中的HTML标头中添加“无缓存”标头,至少是为了开发。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container book-wrapper">
<div class="row">
<div class="container book-box">
<div class="row row-one">
<div class="col-md-4 col-sm-4 col-4">
<img src="http://via.placeholder.com/200x200">
</div>
<div class="col-md-8 col-sm-8 col-8">
<h2 id="book-title">Title</h2>
<span id="book-desc">This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random ndom stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is random stuff This is rand stuff </span>
</div>
</div>
</div>
</div>
如果遇到问题,您还可以强制浏览器清除其缓存。
如果您想重建'staticfiles'目录,可以运行命令:
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
您不需要停止/重新启动django服务器,它对Web文件(HTML / JS / CSS)没有影响。
答案 1 :(得分:0)
我认为您必须使用此命令从服务器实例收集静态文件:
./manage.py collectstatic
然后将考虑静态文件中的更新。
答案 2 :(得分:0)
这是浏览器缓存问题。您可以通过多种方式解决它,但我发现最简单的方法是尝试浏览器的 隐身 或 隐私 模式。您将立即看到 css 文件的每一个更改。