【问题标题】:gentelella for django doesn't recognize changes on custom.cssdjango 的 gentelella 无法识别 custom.css 上的更改
【发布时间】:2018-08-11 05:05:42
【问题描述】:

我正在尝试为 django 应用 gentelella 引导模板,因此我将 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 所做的任何更改。

【问题讨论】:

  • 在检查对 CSS 所做的更改之前,您是否清除了浏览器缓存?

标签: python html css django gentelella


【解决方案1】:

In 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()

【讨论】:

    猜你喜欢
    • 2015-02-08
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 2018-01-27
    • 2016-02-17
    • 1970-01-01
    相关资源
    最近更新 更多