css - 无法在 Django 模板中加载字体

标签 css django import django-templates font-face

好吧,我的

STATIC_URL = '/static/'

这就是我的元素文件夹中的内容。

.:
mange.py project projectApp

./projectApp:
__init__.py
models.py
views.py
urls.py
tests.py
static
templates

./projectApp/static:
css

./projectApp/static/css:
consola.ttf style.css

./projectApp/templates:
base.html    

我在导入 style.css 时也遇到了问题。我试过了

    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" />

但它不起作用。

在我的 style.css 中,我试图通过这样做来导入字体

@font-face { font-family: consola; src: url('consola.ttf'); }

我的 STATIC_URL 是

STATIC_URL = '/static/'

我的 STATIC_ROOT 是

STATIC_ROOT = '/home/user/documents/project/projectApp/static'

但它不起作用。知道怎么做吗?

最佳答案

好的,找到答案了。要正确链接 CSS,我应该这样做

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

代替

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" />

关于css - 无法在 Django 模板中加载字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19202286/

相关文章:

html - 使div居中对齐

python - 将 mongoengine.connect 从 django 中的 setting.py 中取出

javascript - 从服务器返回许多 json 对象的 observable 会一次包含所有对象还是遍历?

R - 文本挖掘 - 导入语料库并将文件名保留在文档术语矩阵中

php - 导航栏没有使用 Bootstrap 4 的样式

css - 遗留 flex 盒的基线对齐

django - 为什么当我运行 "No fixtures found."命令时得到 "python manage.py syncdb"?

mysql - 导入存储过程时出现错误1064

MySQL汇总状态表,用于存储操作结果

html - 具有半透明背景图像的白色文本的 css 背景颜色