請你幫助我好嗎?
我正在嘗試在網站上添加一個 css 檔案。
本網站由flask、html、css制作并上傳到HEROKU。當我只是在 HTML 中時,主頁正常作業,現在我鏈接了 css,我得到了這個錯誤:
內部服務器錯誤
服務器遇到內部錯誤,無法完成您的請求。服務器過載或應用程式出錯。
當我移動到沒有 css 的其他頁面時,它可以作業,但我不知道出了什么問題。
HTML:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='css/reset.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/homepage.css') }}">
<title>HomeD3v</title>
</head>
<body>
<h1>nogD3V</h1>
<h2>BUILDING</h2>
</body>
</html>
PYTHON:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def homepage():
return render_template("homepage.html")
@app.route("/contatos")
def contatos():
return render_template("contatos.html")
@app.route("/usuarios/<nome_usuario>")
def usuarios(nome_usuario):
return render_template("usuarios.html", nome_usuario=nome_usuario)
if __name__ == "__main__":
app.run(debug=True)
結構體
uj5u.com熱心網友回復:
那么在你的情況下,靜態目錄應該在你的專案的根目錄中而不是在模板目錄中,所以它應該是這樣的
/
static/
└── css/
└──style.css
templates/
└── base.html
main.py
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/styles.css')}}">
在此鏈接中,您可以看到燒瓶專案布局
https://flask.palletsprojects.com/en/2.1.x/tutorial/layout/
uj5u.com熱心網友回復:
我試過了,但沒有用。
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static//static/reset.css HTTP/1.1" 308 -
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static//static/homepage.css HTTP/1.1" 308 -
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static/static/reset.css HTTP/1.1" 404 -
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static/static/homepage.css HTTP/1.1" 404 -
然后我做了一些測驗:
<link rel="stylesheet" href="{{ url_for('static', filename='/static/reset.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='/static/homepage.css') }}">
<link rel="stylesheet" href="/static/homepage.css">
<link rel="stylesheet" href="/static/reset.css">
我得到了:
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static/static/reset.css HTTP/1.1" 404 -
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static/static/homepage.css HTTP/1.1" 404 -
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static/homepage.css HTTP/1.1" 200 -
127.0.0.1 - - [12/Jun/2022 23:34:48] "GET /static/reset.css HTTP/1.1" 200 -
出于某種原因,我無法使用 sintax 上傳檔案:{{ url_for('static', filename='/static/reset.css') }}
當我在沒有 python sintaxe 的情況下運行代碼時,CSS 顯示在頁面上。但為什么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/489526.html
上一篇:反應原生TextInput:當TextInput被禁用時,如何使文本顏色(或樣式)不改變?
下一篇:如何測驗頁面上的文本被洗掉
