首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当试图在浏览器窗口中加载我的烧瓶应用程序时,"URL未找到错误“

当试图在浏览器窗口中加载我的烧瓶应用程序时,"URL未找到错误“
EN

Stack Overflow用户
提问于 2020-02-24 09:42:45
回答 1查看 355关注 0票数 0

下面是我的密码。我想通过我的烧瓶应用程序将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

我该怎么办?下面是我的应用程序代码:

代码语言:javascript
运行
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-24 10:03:52

由于您已经在路由@app.route("/upload", methods=['GET', 'POST'])下定义了应用程序逻辑,并且没有在基本地址:@app.route("/", methods=['GET', 'POST'])下定义任何逻辑,所以必须使用以下方式加载应用程序:

代码语言:javascript
运行
复制
http://127.0.0.1:5000/upload

如果您在您的烧瓶应用程序中使用任何其他主机地址或端口号,则必须将您的URL更改为:

代码语言:javascript
运行
复制
http://Your_flask_IP_Address:Port_Number/upload

如果这样做有效,请发表评论。干杯!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60373110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档