[英]Cannot link to CSS in HTML
我无法链接到HTML中的CSS,但路径正确。 我已经尝试了一切,甚至魔术也无济于事。
romanchenko_test_task/templates/hello.html
romanchenko_test_task/static/first-style.css
hello.html:
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/first-style.css">
</head>
<body>
<p> Hello world </p>
</body>
</html>
first-style.css:
body {
background: blue;
color: white;
}
您的相对链接不正确。
您的两个文件夹路径是:
romanchenko_test_task/templates/hello.html
romanchenko_test_task/static/first-style.css
因此,要退出templates
文件夹,您需要使用../
一级
尝试:
<link rel="stylesheet" type="text/css" href="../static/first-style.css">
谢谢大家
<link rel="stylesheet" type="text/css" href="../static/first-style.css">
将CSS正确链接到HTML。 我的问题是我忘记为静态文件(* .css)编写处理程序,因此龙卷风(python框架)无法识别它们。
亨德勒应该看起来像:
handlers=[(r'/', MainHandler)],
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True)
您从中调用CSS的目录不正确。 您应该使用C:/romanchenko_test_task/static/first-style.css
(整个目录)来调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.