为了账号安全,请及时绑定邮箱和手机立即绑定

如何修复路由 GET POST 的“Flask 404”

如何修复路由 GET POST 的“Flask 404”

慕沐林林 2022-06-07 16:58:31
我从 Flask 开始。我有以下view.py我的问题是关于路线@app.route('/uploaded'...from flask import render_template, jsonify, Flask, redirect, url_for, requestfrom app import appimport randomimport osfrom keras.applications.resnet50 import ResNet50from keras.preprocessing import imagefrom keras.applications.resnet50 import preprocess_input, decode_predictionsimport numpy as np@app.route('/')@app.route('/upload')def upload_file2():   return render_template('index.html')@app.route('/uploaded', methods = ['GET', 'POST'])def upload_file():   if request.method == 'POST':      f = request.files['file']      path = os.path.join(app.config['UPLOAD_FOLDER'], f.filename)      model= ResNet50(weights='imagenet')      img = image.load_img(path, target_size=(224,224))      x = image.img_to_array(img)      x = np.expand_dims(x, axis=0)      x = preprocess_input(x)      preds = model.predict(x)      preds_decoded = decode_predictions(preds, top=3)[0]       print(decode_predictions(preds, top=3)[0])      f.save(path)      return render_template('uploaded.html', title='Success', predictions=preds_decoded, user_image=f.filename)@app.route('/index')def index():    return render_template('index.html', title='Home')@app.route('/map')def map():    return render_template('map.html', title='Map')@app.route('/map/refresh', methods=['POST'])def map_refresh():    points = [(random.uniform(48.8434100, 48.8634100),               random.uniform(2.3388000, 2.3588000))              for _ in range(random.randint(2, 9))]    return jsonify({'points': points})@app.route('/contact')def contact():    return render_template('contact.html', title='Contact')在 .html 文件中,经过一些验证步骤后,我要求 End Under 上传一个文件(一张图片)。然后在我下面的代码中,输入是图像,我希望输出结果,必须显示在 上传的文件中。但是,当我访问localhost:5000时,我无法访问upload.htmlURL 是否卡在我的 PHP 请求中(用于在我的home.html中上传文件的请求)对于类似的问题,我从该站点阅读了许多不同的答案,但没有一个能解决我的问题。
查看完整描述

2 回答

?
红糖糍粑

TA贡献1815条经验 获得超6个赞

在您的view.py中,在索引级别,试试这个:


@app.route('/index')

@app.route('/')

def index():

    return render_template('index.html', title='Home')

您可以通过键入localhost:5000或localhost:5000/index来访问该站点


@app.route('/')如@frankie567 所指出的,删除顶部()的路线。


查看完整回答
反对 回复 2022-06-07
?
忽然笑

TA贡献1806条经验 获得超5个赞

使用不同的端口号对我有用!不知道为什么这会起作用,因为我有一个在端口 8000 上运行的替代烧瓶应用程序。谢谢。



查看完整回答
反对 回复 2022-06-07
  • 2 回答
  • 0 关注
  • 211 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号