gpt4 book ai didi

css - django 添加样式表到站点

转载 作者:太空宇宙 更新时间:2023-11-04 15:47:08 25 4
gpt4 key购买 nike

学习如何将样式表添加到 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:visual quick pro guide”一书中学习django。所有代码看起来都是正确的。不过,我在书中发现了一些错误。任何帮助将不胜感激。

谢谢,鲍比

最佳答案

您的 URLconf 映射“/stylesheets/”,但您的 HTML 正在查看“/var/chapter6/stylesheets”。

关于css - django 添加样式表到站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11614146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com