我在我的urls.py系列中有:
if settings.DEBUG==True:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT})
)在我的设置文件中,如下所示:
STATIC_DOC_ROOT = os.path.join(os.path.dirname(__file__),'static').replace('\\','/')当我转到/在我的页面中,一切都工作得很好。当我点击来自/指向另一个页面的链接时,由于404错误,我没有应用CSS。他尝试从该URL加载CSS文件。
http://localhost:8000/show/sth/static/style.css下面是此方法的urls.py
(r'^show/(?P<subject>[^/]+)/(?P<title>[^/]+)$','show'),我有网址,/links和css的工作只是在这一个模板,它不工作。看起来这些参数把事情搞乱了。有什么建议可以解释这个失败的原因吗?下面是我的模板代码:
{% extends "szkielet.html" %}
{% block tresc %}
<div id="content">
<div class="post">
<h2 class="title">{{ notatka.tytul }}</h2>
<p class="meta"><span class="author">{{ notatka.user.name }}</span> <span class="date">July 07, 2010</span> <span class="links"><a href="#" title="">Comments</a></span></p>
<div class="entry">
<p>{{ notatka.tresc }}</p>
</div>
</div>
</div>
{% endblock %}Szkielet.html -它是我的基础
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Perfect Blemish by Free CSS Templates</title>
<link href="{{ MEDIA_URL }}style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>这是负责CSS的一部分,它只是一个样式表。
发布于 2011-03-07 00:55:36
url可能会被设置为覆盖静态url路径,但这里不是这种情况!因此,您的URL配置文件与此无关。
核心问题是你的模板呈现了一个不正确的URL:http://localhost:8000/show/sth/static/style.css应该是http://localhost:8000/static/style.css正确的吗?
向我们展示您的模板,因为这似乎是问题所在。在我看来,您只是为CSS设置了一个相对URL,而不是绝对或/static/style.css。
你的{{ media_url }}是什么?它应该是绝对的,并且以/开头
https://stackoverflow.com/questions/5211345
复制相似问题