0

我正在尝试为 django 应用 gentelella bootstrap 模板,因此我将app目录复制到了我自己的 django 项目中。我正在使用一些现成的 html 模板,所以我将它们复制到templates适当的应用程序的目录中,但我将所有静态内容保留在app目录中。问题是当我修改app/static/build/css/custom.css文件时,因为我的 html 文件没有反映更改。

在这种情况下,我将新类添加yellowcustom.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.

4

1 回答 1

0

在 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()
于 2018-03-02T22:40:50.053 回答