1、使用模板:
@app.route('/')defhome():return render_template("homepage.html")#homepage.html在templates文件夹下
2、使用 send_from_directory
root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "html")#html是个文件夹
@app.route('/')defhome():return send_from_directory(root, "homepage.html")#homepage.html在html文件夹下
3、使用 app.send_static_file
app = Flask(__name__,static_url_path='')#修改静态文件夹的目录
@app.route('/')defhome():return app.send_static_file('homepage.html')#homepage.html在static文件夹下
4、flask 调用 css文件
app = Flask(__name__,static_url_path='')
@app.route('/')defhome():return app.send_static_file('html/homepage.html')
#html里面引用css
文件夹结构目录
注意:css文件必须在静态文件夹下,否则css调