在我网站上的一个模板中,我有一个来自 bootstrap 的字形图标。每次我请求该页面时,我都会在终端中收到 404 错误且没有图标。奇怪的是,该页面作为普通静态页面工作,而不是从我的开发服务器提供的。这是目录布局:
-static
-css
-fonts
-js
-images
-admin
-templates
-relevant template
这是其中一个失败请求的输出:
GET /fonts/glyphicons-halflings-regular.ttf HTTP/1.1" 404
对我来说,这看起来像是期望字体文件夹位于根目录中,但是当我将文件夹放在那里时,它仍然没有找到它。
有人有什么想法吗?让我知道还有哪些有用的信息。谢谢
最佳答案
staticfiles
应用程序需要正确配置
-
settings.INSTALLED_APPS
应该有django.contrib.staticfiles
- 配置
setttings.STATIC_URL
正确 - 在你的模板中,使用
{% load staticfile %} <img src="{% static 'img/foo.png' %}
但要小心,你don't want django to be serving staticfiles in production
关于html - Django 开发服务器不提供 bootstrap 3 glyphicons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38066985/