包括Django中的css [英] including css in Django

查看:119
本文介绍了包括Django中的css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我读了这个,并试图做同样的事情,但不适合我。 >

我的模板:

  {%load static%}< html>< ; head>< link href ={%get_static_prefix%} / style.css ='stylesheet'type ='text / css'/>< / head>< body> 

我得到的HTML:

 < head>< link href =C:/Users/Nayish/workspace/am/src/am/static/style.css ='stylesheet'type ='text / css '/>< / head> 

请注意,这是包含我的CSS的文件夹。



谢谢Boris。

解决方案

我猜你没有使用静态CSS表。我一直在做:

 < html> 
< head>
{%block stylesheet%}
< style type =text / csstitle =currentStyle>
@import{{MEDIA_URL}} css / style.css;
< / style>
{%endblock stylesheet%}
....

然后我设置我的媒体根,并将文件存储为

  MEDIA_ROOT =< fullyquallified patyh> / Media / css /< css文件> 
MEDIA_URL = http:// localhost / mysite /

应该注意 STATIC_URL 默认为 MEDIA_URL 如果未定义。


I'm new to Django, and i'm having hard time including css styles in a template.

I read this and tried to do the same but it's not working for me.

my Template:

{% load static %}<html><head><link href="{% get_static_prefix %}/style.css" rel='stylesheet' type='text/css' /></head><body>

the HTML i get:

<head><link href="C:/Users/Nayish/workspace/am/src/am/static/style.css"rel='stylesheet'type='text/css' /></head>

Note that this is the folder containing my css.

Thanks, Boris.

解决方案

I am guessing you aren't using static css sheets. I always just do:

<html>
<head>
            {%block stylesheet %}
               <style type="text/css" title="currentStyle"> 
                   @import "{{MEDIA_URL}}css/style.css";
               </style>
            {% endblock stylesheet%}
   ....

I then set my Media root, and store the files as

 MEDIA_ROOT=<fullyquallified patyh>/Media/css/<css files>
 MEDIA_URL=http://localhost/mysite/

It should be noted that STATIC_URL defaults to MEDIA_URL if its not defined.

这篇关于包括Django中的css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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