亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復路由 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 [email protected]('/')@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 關注
  • 212 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號