2016-08-24 48 views
2

当我打开我的页面我在我的终端以下消息:我的Django项目没有加载引导glyphicons

Not Found: /fonts/glyphicons-halflings-regular.woff2                           
[24/Aug/2016 17:19:36] "GET /fonts/glyphicons-halflings-regular.woff2 HTTP/1.1" 404 2238                  
Not Found: /fonts/glyphicons-halflings-regular.woff                            
[24/Aug/2016 17:19:36] "GET /fonts/glyphicons-halflings-regular.woff HTTP/1.1" 404 2235                   
Not Found: /fonts/glyphicons-halflings-regular.ttf 

我home_page代码,我加载此glyphicon高于:

{% load staticfiles %} 
<link rel="stylesheet" type="text/css" href="{% static 'bootstrapmin.css' %}"/> 
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}" /> 

<nav class="navbar navbar-inverse"> 
    <div class="container-fluid"> 
     <a class="navbar-brand" href=""> 
      <span class="glyphicon glyphicon-log-out" aria-hidden="true"></span>&nbsp 
      <button class="btn-link" type="button"> OntoLogica</button> 

     </a>   
    </div> 
</nav> 

我的引导文件是:

  • 我的项目文件夹
    • 静态文件夹
      • bootstrapmin.css
      • 的style.css
      • Fonts文件夹
        • 以下是文件Django的找不到

我已经尝试做的事:

  1. 移动字体文件夹的自举
  2. 的同一路径下的文件移动字体的静态文件夹之外文件夹。

如果您需要我没有提供的任何信息,请问,我会。 伙计们,什么是错的?预先感谢任何帮助!

+0

你运行过'./manage.py collectstatic'吗?此外,“我的项目文件夹”是一个应用程序的文件夹,还是它真的是您的项目中的顶级文件夹?如果它是一个应用程序,您可以尝试使用'“{%static'my_project_or_app/bootstrapmin.css'%}”'而不是仅仅使用'“{%static'bootstrapmin.css'%}”'。 – elethan

+0

是的,我运行了collectstatic。我的项目文件夹是顶级项目。命令“{%static'bootstrapmin.css'%}”工作正常,因为我可以访问引导程序命令,例如navbars等。特定情况下不起作用的是glyphicon。是什么有关没有找到我认为的字体和svg文件。 –

回答

2

默认情况下,引导的CSS定义了看起来像这样的字体相对路径:

../fonts/glyphicons-halflings-regular.woff2 

这意味着浏览器将尝试从其中CSS文件是一个fonts目录中查找一级目录。在你的项目结构的情况下,它意味着它试图获取/fonts/glyphicons-halflings-regular.woff2而不是/static/fonts/glyphicons-halflings-regular.woff2,这是他们实际存在的地方。

最简单的办法是坚持directory structure recommended in the documentation,并把所有的CSS的css目录内即在同一级别的网站为fonts目录:

- static 
    - css 
     - bootstrap.min.css 
     - style.css 
    - fonts 
     - glyphicons-halflings-regular.woff2 

很明显,你现在必须参照与css前缀的文件:

<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> 
<link rel="stylesheet" href="{% static 'css/style.css' %}"> 

更复杂的解决方案,您可以设置自定义下载customised版本引导的@icon-font-path(注意默认:"../fonts/")。利用您当前的项目结构,您需要将其更改为"/static/fonts/"