title: Why i keep getting 'Request' object has no attribute 'file' in Flask while i'm gonna proccess upload images?
body: <p>so i'm gonna make a website about image classification with user input upload image and and the image will be proccessed in different python file, unfortunately i stuck with this problem over a week</p>
  
  <pre><code>AttributeError: 'Request' object has no attribute 'file'
  </code></pre>
  
  <p>this is the full code of Flask<br>
  <strong>app.py</strong></p>
  
  <pre><code>from flask import Flask, redirect, render_template, request
  from werkzeug.utils import secure_filename
  import os
  from Testing import predict
  
  app = Flask(__name__)
  
  
  app.config["ALLOWED_EXTENSIONS"] = ["JPEG", "JPG", "PNG", "GIF"]
  app.config['UPLOAD_FOLDER'] = 'uploads'
  
  def allowed_image(filename):
  
      if not "." in filename:
          return False
  
      ext = filename.rsplit(".", 1)[1]
  
      if ext.upper() in app.config["ALLOWED_EXTENSIONS"]:
          return True
      else:
          return False
  
  
  @app.route('/predict_image/', methods=['GET', 'POST'])
  def render_message():
      # Loading CNN model
      if request.method == 'POST':
          file = request.file['image_retina']
          if 'file' not in request.files:
              return render_template('upload.html')
  
          if file.filename == '':
              return render_template('upload.html')
  
          if file and allowed_image(file.filename):
              filename = secure_filename(file.filename)
              file.save(os.path.join(app.config['UPLOAD_FOLDER'],  filename))
  
      predict()
      return render_template('upload.html')
  </code></pre>
  
  <p>and this is the code where the image will be proccessed<br>
  <strong>Testing.py</strong>  </p>
  
  <pre><code>import os
  import numpy as np
  from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
  from keras.models import Sequential, load_model
  import time
  
  start = time.time()
  
  # Define Path
  
  test_path = 'data/test_image'
  
  
  
  
  # Define image parameters
  img_width, img_height = 150, 150
  
  # Prediction Function
  
  
  def predict():
      model_path = './models/model.h5'
      model_weights_path = './models/weights.h5'
      model = load_model(model_path)
      model.load_weights(model_weights_path)
      x = load_img(test_path, target_size=(img_width, img_height))
      x = img_to_array(x)
      x = np.expand_dims(x, axis=0)
      array = model.predict(x)
      result = array[0]
      # print(result)
      answer = np.argmax(result)
  
       if answer == 0:
           print("Predicted: Drusen")
       elif answer == 1:
           print("Predicted: Normal")
  
      return answer
  
  
  # Calculate execution time
  end = time.time()
  dur = end-start
  
  if dur &lt; 60:
      print("Execution Time:", dur, "seconds")
  elif dur &gt; 60 and dur &lt; 3600:
      dur = dur/60
      print("Execution Time:", dur, "minutes")
  else:
      dur = dur/(60*60)
      print("Execution Time:", dur, "hours")
  </code></pre>
  
  <p><strong>upload.html</strong></p>
  
  <pre><code>&lt;html lang="en"&gt;
  
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Upload Gambar&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h1&gt;Upload an Image&lt;/h1&gt;&lt;br&gt;
      &lt;form method="post" enctype="multipart/form-data"&gt;
          &lt;input type="file" id="image_retina" name="image_retina"&gt;
          &lt;label for="image_retina"&gt;Select image...&lt;/label&gt;&lt;br&gt;
  
          &lt;button type="submit"&gt;Upload&lt;/button&gt;&lt;br&gt;
          &lt;!-- &lt;a href="/predict_image"&gt;bercanda anda&lt;/a&gt; --&gt;
      &lt;/form&gt;
  
      {% if message %}
      &lt;p&gt;{{message}}&lt;/p&gt;&lt;br&gt;
  
  
      {% if data.shape[0] &gt; 0 %}
  
      &lt;!-- {{ data.reset_index(drop = True).to_html(classes="table table-striped") | safe}} --&gt;
  
      {% endif %}
  
      &lt;p&gt;&lt;img src="{{image_retina}}" style='width:500px' /&gt;&lt;br&gt;
  
          {% endif %}
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>thank you so much!!</p>