由于某些原因,我的 CSS 规则没有被应用。我知道 css 页面被找到并加载到浏览器中。只是规则没有被应用。我试过只执行 h1 规则,但我的规则未应用于页面。我在 ubuntu 12.04 服务器上使用 uwsgii 和 nginx。我已经收集了我的静态文件,重新启动了 uwsgi 和 nginx,我已经更改了规则,我添加了 !important,我遗漏了一些东西,我不知道它是什么。任何帮助将不胜感激。
目前我的 css/base.css 看起来像这样 - 我也尝试过将颜色更改为红色但不是。
.evil {
color: #c5e3bf;
}
我的基本模板 - 如下所示:
<!DOCTYPE html>
<html>
<head>
<title>{% block sub_title %}{% endblock %} Awesome title</title>
{% load staticfiles %}
<link rel="stylesheet/css" type="text/css" href='{% static "css/base.css" %}'>
<script type="text/javascript" src="{% static 'jquery-2.1.0.js' %}"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.js"></script>
<script type="text/javascript" src="{% static 'Underscore.js' %}"></script>
<script type="text/javascript" src="{% static 'Restangular.js' %}"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>
<script src="{% static 'js/ng-sign-in/app.js' %}"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<body>
<span class="evil">Punch something, you know you wanna. Just do it.</span>
</body>
</html>
更新:我注释掉了所有的脚本,只留下
<link rel="stylesheet/css" type="text/css" href='/static/css/base.css'>
仍然没有应用规则。
更新:从在 nginx 上运行更改为在本地主机上运行 - 仍然没有运气 我的设置:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
我的网址:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView
from django.conf import settings
from django.conf.urls.static import static
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls),
url(r'^$', HomeView.as_view(), name='home'),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) # this was added in per request -- notta.
最佳答案
尝试在您的 urls.py 中添加 + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT):
urlpatterns = patterns('', #Your URLS) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
关于html - 未应用 CSS 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23034644/