0
我想在我的基於Flask的網站上設置一些元素的樣式,但由於某種原因,我的css文件從未加載。404錯誤在Flask中的CSS文件
雖然情況是特殊的,從layout.html
調用的路徑爲/static/css/
時,文件加載正常,但由於某種原因,頁面第二次將路徑截斷爲/css/
,並生成404
錯誤。
這是我的瓶項目的結構:
Directory Structure:
+app
+static
+css
style-large.css
style.css
style-xlarge.css
+templates
index.html
layout.html
片段的layout.html
:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block doc_title %} {% endblock %}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/skel.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/skel-layers.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/init.js') }}"></script>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/skel.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style-xlarge.css') }}" />
<!-- <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" /> -->
<!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]-->
</head>
的特點是這樣的;不管我怎麼網址更改爲文件steyl-large.css
,style.css
和style-xlarge.css
,我總是得到一個404
錯誤,看起來像這樣:
127.0.0.1 - - [05/Dec/2015 17:34:20] "GET /static/css/style-xlarge.css HTTP/1.1" 304 -
127.0.0.1 - - [05/Dec/2015 17:34:20] "GET /static/css/style.css HTTP/1.1" 304 -
127.0.0.1 - - [05/Dec/2015 17:34:20] "GET /css/style-large.css HTTP/1.1" 404 -
127.0.0.1 - - [05/Dec/2015 17:34:20] "GET /css/style.css HTTP/1.1" 404 -
127.0.0.1 - - [05/Dec/2015 17:34:20] "GET /css/style-xlarge.css HTTP/1.1" 404 -
前兩個要求,導致304
代碼做工精細的那些和在我的頁面上呈現幾乎所有東西,但是在它沒有的情況下。
我不知道爲什麼會發生這種情況。我認爲這可能是爲什麼我的網頁上的元素未被設置樣式的原因,但我不知道它爲什麼會發生。
你設置了你的'static_url_path'嗎? –