html - Django bower , Bootstrap ,静态文件不起作用

标签 html css django twitter-bootstrap bower

我在从 Django 模板加载静态文件时遇到问题。

这是我的设置:

INSTALLED_APPS = (                                                                                  
 33     'django.contrib.admin',                                                                         
 34     'django.contrib.auth',                                                                          
 35     'django.contrib.contenttypes',                                                                  
 36     'django.contrib.sessions',                                                                      
 37     'django.contrib.messages',                                                                      
 38     'django.contrib.staticfiles',                                                                   
 39     'chat',                                                                                         
 40     'ws4redis',                                                                                     
 41     'djangobower',                                                                                  
 42 )                                                                                                                                                                                                
 44 MIDDLEWARE_CLASSES = (                                                                              
 45     'django.contrib.sessions.middleware.SessionMiddleware',                                         
 46     'django.middleware.common.CommonMiddleware',                                                    
 47     'django.middleware.csrf.CsrfViewMiddleware',                                                    
 48     'django.contrib.auth.middleware.AuthenticationMiddleware',                                      
 49     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',                               
 50     'django.contrib.messages.middleware.MessageMiddleware',                                         
 51     'django.middleware.clickjacking.XFrameOptionsMiddleware',                                       
 52 )                                                                                                                                                                                                       
 54 ROOT_URLCONF = 'chrum.urls'                                                                         

 68 STATIC_ROOT = os.path.join(BASE_DIR, 'static')                                                      

 70 STATICFILES_FINDERS  = ("django.contrib.staticfiles.finders.FileSystemFinder",                      
 71                         'django.contrib.staticfiles.finders.AppDirectoriesFinder',                  
 72                         'djangobower.finders.BowerFinder',)                                         
 73 STATICFILES_DIRS = (                                                                                
 74     os.path.join(BASE_DIR, "components"),                                                           
 75 )                                                                                                
 77 BOWER_COMPONENTS_ROOT = os.path.join(BASE_DIR, 'static')                                            
 78 BOWER_INSTALLED_APPS = ('bootstrap',)

这是我的模板:

 4 {% load staticfiles %}                                                                              
  5 {% load static from staticfiles %}                                                                  
  6 <script src="{% static 'components/bower_components/jquery/dist/jquery.js' %}"></script>                                                                                                
  7 <script src="{% static 'components/bower_components/bootstrap/dist/js/bootstrap.js' %}"></script>   
  8 <script rel="stylesheet" type="text/css"  src="{% static 'components/bower_components/bootstrap/dist/css/bootstrap.css' %}"></script>

在站点源代码中,我可以看到该链接有效,并且我可以读取我的 css 文件。

服务器返回:

[05/Dec/2014 21:45:52]“获取/static/components/bower_components/jquery/dist/jquery.js HTTP/1.1”304 0 [2014 年 12 月 5 日 21:45:52]“GET/static/components/bower_components/bootstrap/dist/js/bootstrap.js HTTP/1.1”304 0 [05/Dec/2014 21:45:52] “GET/static/components/bower_components/bootstrap/dist/css/bootstrap.css HTTP/1.1” 304 0

但是那个 css 不起作用,我在浏览器的样式编辑器中看不到它。

ps:如果我在我的浏览器中手动导入该 css 文件,它就可以工作!

最佳答案

您似乎没有在 settings.py 文件中定义 STATIC_URL 变量。添加以下行您的设置:

STATIC_URL = '/static/'

关于html - Django bower , Bootstrap ,静态文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27325403/

相关文章:

html - {分页后 : always} not working when printing

javascript - jquery 旋钮使用 CSS 改变颜色

html - 从具有渐变颜色的周围 div 继承 Bootstrap 按钮文本颜色

python - Django makemessage 命令不处理应用程序

javascript - http 形式的文本区域的 req.body 为空(使用 Express)

javascript - 我需要将 0 或 1 存储到服务器 php 中的 .status 文件

javascript - 颜色 slider 渐变

python - django-redis 无效的数据库索引错误和 redis url 的含义

django - 在 django 模板中显示 django-pandas 数据框

overflow - 在外部 div 上使用 CSS max-height 强制在内部 div 上滚动