在Django中没有加载CSS文件 [英] CSS file not loading in Django
本文介绍了在Django中没有加载CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以提供您的投入吗
urls.py
from django.conf.urls.defaults import patterns,include,url
from preview,view import *
import os
site_media = os .path.join(os.path.dirname(__ file __),'site_media')
urlpatterns = patterns('',
(r'^ catalog / $','home') ,
(r'^ site_media /(?P< path>。*)$,'django.views.static.serve',{'document_root':site_media}),)
css.css
code> * {
margin:0;
padding:0;
}
html {
font-size:medium;
}
html,body {
background-color:Silver;
}
.cb {
clear:both;
}
.fr {
float:right;
}
.fl {
float:left;
}
.bn {
border:none;
} #main {
margin:0 auto;
width:900px;
背景颜色:白色;
}
.bannerIEPadder,.sidebarIEPadder,.contentIEPadder {
padding:10px;
}
.navIEPadder,.footerIEPadder {
padding:5px;
}
#banner {
width:900px;
height:75px;
background-color:DarkOrange;
颜色:白色;
font-size:36px;
font-weight:bold;
position:relative;
}
div.cart_box {
position:absolute;
顶部:10px;
right:10px;
font-size:medium;
}
div.cart_box a {
color:white;
}
#sidebar {
width:200px;
float:left ;;
}
#content {
width:700px;
float:left;
}
#footer {
clear:both;
background-color:#98AC5E;
颜色:白色;
text-align:center;
}
a.skip_link {
position:absolute;
left:-1000px;
顶部:-1000px;
}
base.html
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // ENXHTML1-s.dtd>< html
$ / pre>
xmlns =http://www.w3.org/1999/xhtmlxml:lang =enlang =en>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> {%block title%} {%if page_title%} {{page_title}} - {%endif%}
{{site_name}} {%endblock%}< / title> ;
< meta name =keywordscontent ={{meta_keywords}}/>
< meta name =descriptioncontent ={{meta_description}}/>
< link rel =stylesheethref =/ site_media / css.css
type =/ text / css/>
< / head>
< body>
{%block site_wrapper%} {%endblock%}
< / body>< / html>
catalog.html
{%extendsbase.html%}
{%block site_wrapper%}
< div id =main> ;
< a href =#contentclass =skip_link>跳到主要内容< / a>
< div id =banner>
< div class =bannerIEPadder>
< div class =cart_box>
[链接到购物车]
< / div>
现代音乐家
< / div>
< / div>
< div id =navigation>
< div class =navIEPadder>
[导航]
< / div>
< / div>
< div id =middle>
< div id =sidebar>
< div class =sidebarIEPadder>
[搜索框]
< br />
[类别列表]
< / div>
< / div>
< div id =content>
< a name =content>< / a>
< div class =contentIEPadder>
{%block content%} {%endblock%}
< / div>
< / div>
< / div>
< / div>
< div id =footer>
< div class =footerIEPadder>
[footer here]
< / div>
< / div>
< / div>
{%endblock%}
index.html p>
{%extendscatalog.html%}
{%block content%}
< H2>!欢迎< / H2>
{%endblock%}
解决方案您的base.html中从/ text / css链接到text / css的链接类型。
I have a CSS file being defined in my program and for some reason its not working...When I check'd with firebug the status is 200 OK but no changes occur..Not sure if there is any syntax issue with my CSS file. Can you please provide your inputs
urls.py
from django.conf.urls.defaults import patterns, include, url from preview,view import * import os site_media = os.path.join(os.path.dirname(__file__),'site_media') urlpatterns = patterns('', (r'^catalog/$','home'), (r'^site_media/(?P<path>.*)$,'django.views.static.serve',{'document_root':site_media}),)
css.css
*{ margin:0; padding:0; } html{ font-size:medium; } html,body{ background-color:Silver; } .cb{ clear:both; } .fr{ float:right; } .fl{ float:left; } .bn{ border:none; }#main{ margin: 0 auto; width:900px; background-color:White; } .bannerIEPadder, .sidebarIEPadder, .contentIEPadder{ padding:10px; } .navIEPadder, .footerIEPadder{ padding:5px; } #banner{ width:900px; height:75px; background-color:DarkOrange; color:White; font-size:36px; font-weight:bold; position:relative; } div.cart_box{ position:absolute; top:10px; right:10px; font-size:medium; } div.cart_box a{ color:white; } #sidebar{ width:200px; float:left;; } #content{ width:700px; float:left; } #footer{ clear:both; background-color:#98AC5E; color:White; text-align:center; } a.skip_link{ position:absolute; left:-1000px; top:-1000px; }
base.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "XHTML1-s.dtd" ><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>{% block title %}{% if page_title %}{{ page_title }} - {% endif %} {{ site_name }}{% endblock %}</title> <meta name="keywords" content="{{ meta_keywords }}" /> <meta name="description" content="{{ meta_description }}" /> <link rel="stylesheet" href="/site_media/css.css" type="/text/css"/> </head> <body> {% block site_wrapper %}{% endblock %} </body></html>
catalog.html
{% extends "base.html" %} {% block site_wrapper %} <div id="main"> <a href="#content" class="skip_link">Skip to main content</a> <div id="banner"> <div class="bannerIEPadder"> <div class="cart_box"> [link to cart here] </div> Modern Musician </div> </div> <div id="navigation"> <div class="navIEPadder"> [navigation here] </div> </div> <div id="middle"> <div id="sidebar"> <div class="sidebarIEPadder"> [search box here] <br /> [category listing here] </div> </div> <div id="content"> <a name="content"></a> <div class="contentIEPadder"> {% block content %}{% endblock %} </div> </div> </div> </div> <div id="footer"> <div class="footerIEPadder"> [footer here] </div> </div> </div> {% endblock %}
index.html
{% extends "catalog.html" %} {% block content %} <h2>Welcome!</h2> {% endblock %}
解决方案Change the type of the link in your base.html from "/text/css" to "text/css".
这篇关于在Django中没有加载CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文