Django从模板加载CSS
好的,所以我的base.html模板是在
okay so my base.html template is in
/home/user/documents/project/app/templates/base.html
我的style.css在
and my style.css is in
/home/user/documents/project/app/static/css/style.css
,我的consola.ttf字体位于
and my consola.ttf font is in
/home/user/documents/project/app/static/fonts/consola.ttf
我的static_URL是
My static_URL is
STATIC_URL = '/static/'
和我的STATIC_ROOT是
and my STATIC_ROOT is
STATIC_ROOT = '/home/user/documents/project/app/static'
现在,如何将style.css链接到我的base.html模板?
我尝试过
now, how do I link the style.css to my base.html template? I tried doing
但它没有工作。另外,如何在我的style.css中加载consola.ttf字体?
由于style.css和consola.ttf字体都在同一个静态文件夹中,所以我尝试过
but it didn't work. Also, how do I load the consola.ttf font in my style.css? Since both style.css and the consola.ttf font are in the same static folder, I tried doing
@font-face { font-family: consola; src: url(../../fonts/consola.ttf'); }
但是也没有。关于如何解决这两个问题的任何想法?
but that didn't work either. Any idea on how to fix these two problems?
这是我的.html模板的开始。
Here is the beginning of my .html template.
<html>
<head>
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" />
<title>{% block title %}Name{% endblock %}</title>
</head>
这是怎么回事,对吗?
好的,找到答案。我应该做
Okay found the answer. I was supposed to do
<link rel="stylesheet" type="text/css" href="{% static "css/style.css" %}" />
而不是
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" />