我试图使用flask在浏览器上打开一个本地文件夹,例如直接在地址栏中键入file:///D:/。但它失败了。当我直接在浏览器上运行home.html时,它可以成功地工作。有什么问题吗?我怎么能告诉Flask工作正确?
感谢app.py
from flask import Flask, render_template, render_template_string
from flask import Flask
app = Flask(__name__)
@app.route("/", methods=['POST', 'GET'])
@app.route('/helloworld')
def helloworld():
return 'Hello, world!', 200
@app.route("/home")
def home():
return render_template('home.html')
home。
<a href="F:/">CLICK</a>
试试这个
@app.route("/home")
def home():
import os
arr = os.listdir("F:/")
return render_template('home.html', arr=arr)
,然后在模板(home.html)中相应地列出你的文件。