[英]style.css not loading in django html template
我創建了一個登錄頁面並調用了 static css 表來進行樣式設置,但它不起作用。 我在 login.html 中加載 static 並使用
<html>
<head>
<title>PWC Login</title>
<link rel="stylesheet" href="{% static 'css/style.css'%}">
</head>
<body>
<div class="loginbox">
<img src="{% static 'images/avatar.png' %}" class="avatar">
<h1 class="h1">Login Here</h1>
<form>
<p>Username</p>
<input type="text" name="" placeholder="Enter Username">
<p>Password</p>
<input type="password" name="" placeholder="Enter Password">
<input type="submit" name="" value="Login">
<a href="#">Forgot your password?</a><br>
<a href="#">Don't have an account?</a>
</form>
</div>
</body>
</html>
css :
body {
margin: 0;
padding: 0;
background: url('static/images/pic1.jpeg');
background-size: cover;
background-position: center;
font-family: sans-serif;
}
.loginbox{
width:320px;
height:420px;
background: #000;
color: #fff;
top:50%;
left:50%;
position: absolute;
transform: translate(-50%,-50%);
box-sizing: border-box;
padding: 70px 30px;
}
.avatar{
width: 100px;
height: 100px;
border-radius: 50%;
position: absolute;
top: -50px;
left: calc(50% - 50px);
}
我分別嘗試了 html 和 css 文件,它工作正常。 背景是 jpeg 文件,登錄框居中。 它必須是 django 中的東西,但不確定它是什么。
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static/"),
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.