Django从模板加载CSS [英] Django loading css from template

查看:207
本文介绍了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" />

这篇关于Django从模板加载CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆