[英]Flask is not reading CSS file
我一直在尋找拼寫錯誤,並嘗試在該網站上找到了一些修復程序,但我的樣式仍然沒有應用。 目錄結構如下:
ResumeSite
----/static
--------/img
------------img1.jpg
------------img2.jpg
--------style.css
----/templates
--------index.html
app.py
CSS文件如下:
/* CSS Variables */
:root {
--primary: #ddd;
--dark: #333;
--light: #fff;
--shadow: 0 1px 5x rgba(104, 104, 104, 0.8);
}
html {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
color: var(--dark);
}
body {
background: #ccc;
margin: 30px 50px;
line-height: 1.4;
}
.btn {
background-color: var(--dark);
color: var(--light);
padding: 0.6rem 1.3rem;
text-decoration: none;
}
.showcase h1 {
color: red;
}
在index.html文件中,我使用Jinja語法正確鏈接了樣式表:
<html>
<head>
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='style.css') }}">
我不確定這是什么問題,當我運行服務器時,我收到一條命令行消息,指出:
GET HTTP:1 200 -
我相信200意味着成功,但是無論我到目前為止嘗試過什么,都不會應用任何樣式。
我無法從您發布的代碼中分辨出來,但是如果您使用的是Boostrap,請確保在引用bootstrap.css
之后對style.css
文件的引用
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='bootstrap.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='style.css') }}">
否則,您的更改將被默認的引導樣式覆蓋
問題很簡單,就是CSS文件位於靜態目錄的頂層,而不位於名為“ css”的子文件夾中。 謝謝@Manish Mahendru提到這一點,將來我將不得不提醒自己燒瓶應用的正確結構。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.