- static_folder表示靜態文件所在路徑,默認爲root_dir下的static文件夾
- static_url_path的行爲比較複雜
- 若是static_folder未被指定(也就是默認值static),那麼static_url_path取爲static
- 若是static_folder被指定了,那麼static_url_path等於static_folder的最後一級文件夾名稱。
- 手動指定static_url_path時,若是static_url_path不爲空串,url的路徑必須以/開頭,如/static。
- 手動指定static_url_path時,若是static_url_path爲空串,url路徑沒必要以/開頭,不然至關於static_url_path=None的狀況,也就是使用static_folder的目錄名字。
- static_path即將廢棄,推薦使用static_path_url
localhost:5000/why/main.pypython
import flask
app = flask.Flask(__name__, static_folder="./", static_url_path="why")
app.run(debug=True)
localhost:5000/main.pyflask
import os
import flask
app = flask.Flask(__name__, static_folder=os.path.abspath("./"), static_url_path="")
app.run(debug=True)