鍍金池/ 問答/PHP  Python  HTML/ python怎樣返回靜態(tài)html文件,不需要渲染

python怎樣返回靜態(tài)html文件,不需要渲染

from flask import Flask,send_file
app = Flask(__name__)

@app.route('/')
def index():
    return send_file("index.html")

if __name__ == '__main__':
    app.run()

這樣可以返回 html 的內(nèi)容,但是奇怪的是 css,js 和圖片資源無法加載,而且靜態(tài)資源路徑肯定沒有放錯

回答
編輯回答
故人嘆

index.html里的靜態(tài)資源的地址不能簡單地寫成在文件系統(tǒng)中相對于index.html的相對地址,而要根據(jù)flask的設(shè)置寫,
或者直接寫成"http://exmaple.com/static/xxx.css"的絕對url

2017年12月3日 08:53