下面是我的密码。我想通过我的烧瓶应用程序将excel文件转换为json。运行代码后,在浏览器中加载烧瓶URL时,localhost会出现以下错误:
404 not found error - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again
我该怎么办?下面是我的应用程序代码:
from flask import Flask, request, jsonify
import flask_excel as excel
app=Flask(__name__)
@app.route("/upload", methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
return jsonify({"result": request.get_array(field_name='file')})
return '''
<!doctype html>
<title>Upload an excel file</title>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file><input type=submit value=Upload>
</form>
'''
@app.route("/export", methods=['GET'])
def export_records():
return excel.make_response_from_array([[1,2], [3, 4]], "csv",
file_name="export_data")
if __name__ == "__main__":
app.run()
发布于 2020-02-24 10:03:52
由于您已经在路由@app.route("/upload", methods=['GET', 'POST'])
下定义了应用程序逻辑,并且没有在基本地址:@app.route("/", methods=['GET', 'POST'])
下定义任何逻辑,所以必须使用以下方式加载应用程序:
http://127.0.0.1:5000/upload
如果您在您的烧瓶应用程序中使用任何其他主机地址或端口号,则必须将您的URL更改为:
http://Your_flask_IP_Address:Port_Number/upload
如果这样做有效,请发表评论。干杯!
https://stackoverflow.com/questions/60373110
复制相似问题