【发布时间】:2015-02-06 15:59:58
【问题描述】:
您好,我是使用 python 和 web 程序的新手,我正在尝试制作一个使用 CSS 样式表的基本网站。我有三个文件:app.py、index.html 和 style.css。它们都在同一个目录中。当我运行 app.py 并转到 localhost:8080 时,它显示“Hello World!”,但它没有 style.css 文件中的样式,并且我的终端显示“HTTP/1.1 GET /style.css” - 404 Not Found .但是,当我在 chrome 中打开我的 index.html 文件而不使用 app.py 文件时,它确实具有样式格式。有什么帮助吗?提前致谢。我的代码如下:
app.py:
import web
urls = (
'/', 'Index'
)
app = web.application(urls, globals())
web.config.debug = True
class Index(object):
def __init__(self):
self.render = web.template.render('.')
def GET(self):
return self.render.index()
if __name__ == '__main__':
app.run()
index.html:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
<title>Basic Web Project</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
style.css:
p {
color: green;
font-size: 22px;
}
【问题讨论】: