问题描述
我对Flask相当陌生,目前正在从事一个项目,该项目的目标是将mp3文件转换为JSON。我决定尝试使用Flask,但是它比我想象的要更具挑战性。
截至目前,我已经能够在我的html页面之一中显示示例JSON文件,但无法对其进行格式化。我看了一些以前的答案,这些答案告诉我使用jsonify,但显然没有奏效。如果你们能帮我忙,那么任何评论都会很感激。这是我的代码:
from flask import Flask,render_template,url_for,request,redirect,json,jsonify
import json
import os
from pathlib import Path
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload',methods=['POST'])
def upload():
file = request.files['inputFile']
if Path(file.filename).suffix == '.mp3':
filename = os.path.join(app.static_folder,'data','json_test.json')
with open(filename) as json_test:
data = json.load(json_test)
return render_template('index2.html',data=data)
else:
return render_template('erro.html')
if __name__ == "__main__":
app.run(debug=True)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)