【发布时间】:2011-03-06 15:26:48
【问题描述】:
我的 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'),
我有 url /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 的部分,它只是一个样式表。
【问题讨论】:
-
我猜你有一个基本的 html 来扩展所有的模板。您是否忘记在此页面上扩展。
-
我有扩展部分。问题是在那个模板中,由于路径错误,css 无法正常工作
标签: django static django-templates