django サイトにスタイル シートを追加する方法を学習します。必要だと思うコードを追加しましたが、サイトはそれを完全に無視します。これが私のファイルです。
urls.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 を学んでいます。すべてのコードは本のように見えます。しかし、私は本にいくつかの間違いを見つけました。どんな助けでも大歓迎です。
ありがとう、ボビー