学习如何将样式表添加到 django 站点。添加了我认为我需要的代码,但该站点完全忽略了它。这是我的文件;
网址.py
import os.path
from django.conf.urls.defaults import *
from users.views import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
stylesheets = os.path.join(os.path.dirname(__file__), 'stylesheets')
urlpatterns = patterns('',
(r'^$', main_page),
(r'^stylesheets/(?P<path>.*)$',
'django.views.static.serve',
{ 'document_root': stylesheets }),
# Examples:
# url(r'^$', 'chapter6.views.home', name='home'),
# url(r'^chapter6/', include('chapter6.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
main_page.html 文件
<html>
<head>
<title>The users application</title>
<link rel="stylesheet"
href="/var/chapter6/stylesheets/style.css"
type="text/css" />
</head>
<body>
<h1>The users application</h1>
Here are the users:
<p>{{ username1 }} </p>
<p>{{ username2 }} </p>
<p>{{ username3 }} </p>
</body>
</html>
最后,这里是样式表。
body {
font-size: 12pt;
background-color: pink;
}
h1 {
color: red;
}
p {
font-size: 20pt;
}
我已经检查了所有代码十几次,找不到任何错误。我正在从“django:视觉快速专业指南”一书中学习 django。所有的代码看起来都是正确的。不过我在书中发现了一些错误。任何帮助将不胜感激。
谢谢,鲍比