【问题标题】:Django not rendering GlyphiconsDjango 不渲染 Glyphicons
【发布时间】:2015-06-29 23:14:48
【问题描述】:

Glyphicon 在我的开发服务器中呈现为空矩形。

设置

from unipath import Path  

BASE_DIR = Path(__file__).ancestor(2)                                   
STATICFILES_DIRS = (BASE_DIR.child("static", "static_dirs"), )        
STATIC_URL = '/static/'       

模板

{% load staticfiles %}
<span class="glyphicon glyphicon-heart"></span> 
<span class="glyphicon glyphicon-calendar"></span>  

bootstrap.css/bootstrap.min.css

src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
    url('../fonts/glyphicons-halflings-regular.woff') format('woff'), 
    url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), 
    url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');

网址

urlpatterns = patterns('',
    url(regex = r'^$',
        view = 'tesglyph.views.testglyph'),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

当我添加到

base.html

<head>
(...)
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css"     rel="stylesheet">(...)
</head>

我得到了心脏,但不是日历!

我该如何解决这个问题?

【问题讨论】:

  • 您是否检查了生成的 html 的准确性?一个有效而另一个无效的一个原因很可能是拼写错误或类名冲突

标签: django twitter-bootstrap glyphicons


【解决方案1】:

这似乎太难了,你考虑过django-bootstrap3之类的吗?

所有需要的将是-

{% load bootstrap3 %}

...

{% bootstrap_icon "heart" %}

请注意,此解决方案意味着您只需在模板中编码,省去了很多麻烦。将 heart 替换为您要显示的引导图标名称。就是这样。

【讨论】:

  • 我已经研究过了,但我倾向于自定义 bootstrap.css。影响大吗?
  • 不是在显示图标方面,只要您的手动引导 css/js 导入发生在使用 {{ bootstrap_css }}{{ bootstrap_js }} 之后,以便您的手动导入优先于 load 语句的自动导入.查看页面的 html 源代码以查看这些语句的内容,并记住最后一次导入 cad 具有每个属性的优先级。
  • 根据您的“它是下面的本地目录”评论,您必须遵循static files 的准则。您不能从生产中的本地目录中提取,而是在您的 STATICFILES_DIRS 设置中搜索所有使用的文件,然后将这些文件复制到您的 STATIC_ROOT。这不仅是最佳实践,而且对于正常运行的站点来说,正确调用具有适当标签的静态文件是必要的。 Read up.
猜你喜欢
  • 2013-09-26
  • 2014-03-17
  • 2018-04-24
  • 2015-10-13
  • 2020-04-02
  • 1970-01-01
  • 1970-01-01
  • 2014-05-08
相关资源
最近更新 更多