鍍金池/ 問答/Python  HTML/ python flask 的 static_floder 的正確路徑應(yīng)該是怎樣的

python flask 的 static_floder 的正確路徑應(yīng)該是怎樣的?

vue 打包后的 dist 文件下目錄是這樣的:

clipboard.png

python是這樣的:

from flask import Flask, render_template

app = Flask(__name__,
        static_folder = "./dist",
        template_folder = './dist')

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

靜態(tài)文件和 index.html 文件都在同一級下,所以代碼里配置的兩個路徑應(yīng)該是用一樣的吧?
結(jié)果報錯了

clipboard.png

但是如果直接在瀏覽器打開 dist 里的 index.html 是正常的,這說明靜態(tài)文件的引入路徑應(yīng)該沒有錯?static_folder 的值寫錯了嗎?

回答
編輯回答
醉淸風

flask 的靜態(tài)文件需要你使用 url_for() 函數(shù)一個一個的導(dǎo)入。你可以參考一下我的項目

1、https://github.com/eastossifr... 這是藍圖設(shè)置的 templates 文件夾和 static 文件夾。
2、https://github.com/eastossifr...
這是一個一個調(diào)用靜態(tài)文件,如 js、css 和 img 文件。

2017年11月4日 10:30