我正在尝试使用 Python 中的 Flask 创建一个简单的 Web 应用程序。我希望这个应用程序执行类似 this 的操作例子。所以我想在 HTML 代码中导入一个 xml 文件。按下按钮时,页面中会出现 xml 的数据。
我的python代码是:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def main():
return render_template('index.html')
if __name__ == "__main__":
app.run()
我的 index.html 代码与 this 相同例子。我在我的计算机中创建了一个 cd_catalog.xml 文件。当我运行我的脚本时,该按钮不执行任何操作。
我的问题是我应该在哪里找到 .xml 文件,以便它可以正确导入到 .html 文件中。
最佳答案
您应该创建一个 static
应用程序模块旁边的目录并将文件放在那里,公共(public)路径将是 /static/***.xml
http://flask.pocoo.org/docs/0.12/quickstart/#static-files
关于Python Flask 应用程序 : include HTML that imports xml file with javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44801607/