我正在尝试为 django 应用 gentelella bootstrap 模板,所以我将 app
目录复制到我自己的 django 项目中。我正在使用一些现成的 html 模板,因此我将它们复制到正确应用程序的 templates
目录中,但我将所有静态内容保留在 app
目录中。问题是当我修改app/static/build/css/custom.css
文件时,因为我的html文件没有反映更改。
在本例中,我将新的类yellow
添加到custom.css
文件中,并将此类添加到index2.html
文件中的某些对象,但文本的颜色没有更改。
这是 django 项目目录树:
├── Attractora
│ ├── ActorsManagerApp
│ │ ├── __init__.py
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── templates
│ │ │ └── ActorsManagerApp
│ │ │ ├── index2.html
│ │ │ └── profile.html
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── Attractora
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── app
│ │ ├── __init__.py
│ │ ├── __init__.pycn-36.pyc
│ │ ├── admin.py
│ │ ├── admin.pyc
│ │ ├── apps.py
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── static
│ │ │ └── build
│ │ │ └── css
│ │ │ └── custom.css
│ │ ├── templates
│ │ │ └── app
│ │ │ └── base_site.html
这是custom.css
文件。yellow
类是我添加的类。
.blue {
color: #3498DB
}
.purple {
color: #9B59B6
}
.green {
color: #1ABB9C
}
.aero {
color: #9CC2CB
}
.red {
color: #E74C3C
}
.yellow {
color: #F1C40F
}
这是index2.html
文件,我将新的yellow
类分配给对象。
<div class="animated flipInY col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="tile-stats">
<div class="icon"><i class="fa fa-info-circle yellow"></i></div>
<div class="count yellow">179</div>
<h3><span class="yellow">Attention</span></h3>
<p>Tasks about to start or finish.</p>
</div>
</div>
<div class="animated flipInY col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="tile-stats">
<div class="icon"><i class="fa fa-warning red"></i></div>
<div class="count red">179</div>
<h3><span class="red">Late</span></h3>
<p>Tasks already due to start or finish.</p>
</div>
</div>
这是base_site.html
文件,其中包含custom.css
文件:
<!-- Custom Theme Style -->
<link href="/static/build/css/custom.css" rel="stylesheet">
我不知道为什么,但我的 html 无法识别我对custom.css
所做的任何更改。
在 Django 1.10 及更高版本中,只需{% load static %}
在模板的顶部。
然后
<link href="{% static 'build/css/custom.css' %}" rel="stylesheet">
并确保在开发服务器中提供静态文件。
# Attractora/Attractora/urls.py
if settings.DEBUG:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()