Колба HTTP POST 404 - PullRequest
       3

Колба HTTP POST 404

0 голосов
/ 25 сентября 2019

Я начинаю на Фляске.У меня есть следующий view.py

Мой вопрос касается маршрута @app.route ('/ uploaded' ...


        from flask import render_template, jsonify, Flask, redirect, url_for, request
        from app import app
        import random
        import os
        from keras.applications.resnet50 import ResNet50
        from keras.preprocessing import image
        from keras.applications.resnet50 import preprocess_input, decode_predictions
        import numpy as np


        @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')
        @app.route('/')
        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, я не могу связаться с uploaded.html

Ошибка:

127.0.0.1 - - [25/ Sep / 2019 19:33:26] "POST /upload.php HTTP / 1.1" 404 -

Я прочитал много разных ответов на этом сайте для похожих проблем, но ни один из них не решил мою проблему.

Заранее спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...