title: TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, but it was a int
body: <p>I have encountered this error while working on my first flask web app. In this app, I am trying to get the distance between two points by using Uber H3 and the haversine formula. I am a beginner in this so any help would be appreciated.:</p>
  <blockquote>
  <p>TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a int.</p>
  </blockquote>
  <pre><code>Traceback (most recent call last)
  File &quot;/Users/shipsy/Documents/flask_tutorial/venv/lib/python3.7/site-packages/flask/app.py&quot;, line 2091, in __call__
  return self.wsgi_app(environ, start_response)
  File &quot;/Users/shipsy/Documents/flask_tutorial/venv/lib/python3.7/site-packages/flask/app.py&quot;, line 2076, in wsgi_app
  response = self.handle_exception(e)
  File &quot;/Users/shipsy/Documents/flask_tutorial/venv/lib/python3.7/site-packages/flask/app.py&quot;, line 2073, in wsgi_app
  response = self.full_dispatch_request()
  File &quot;/Users/shipsy/Documents/flask_tutorial/venv/lib/python3.7/site-packages/flask/app.py&quot;, line 1519, in full_dispatch_request
  return self.finalize_request(rv)
  File &quot;/Users/shipsy/Documents/flask_tutorial/venv/lib/python3.7/site-packages/flask/app.py&quot;, line 1538, in finalize_request
  response = self.make_response(rv)
  File &quot;/Users/shipsy/Documents/flask_tutorial/venv/lib/python3.7/site-packages/flask/app.py&quot;, line 1731, in make_response
  &quot;The view function did not return a valid&quot;
  TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a int.
  </code></pre>
  <pre><code>from flask import Flask, render_template, request
  from flask_sqlalchemy import SQLAlchemy
  import h3
  import googlemaps
  from haversine import haversine
  
  app = Flask(__name__)
  app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
  app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  db = SQLAlchemy(app)
  
  class ETAcalculation(db.Model):
      SNo = db.Column(db.Integer, primary_key=True)
      origin = db.Column(db.String(16), nullable = False)
      destination = db.Column(db.String(16), nullable = False)
      mode = db.Column(db.String(16), default = 'walking')
      # eta = db.Column(db.Integer)
      distance = db.Column(db.Integer)
  
      def __repr__(self):
          return self.distance
      
  @app.route(&quot;/&quot;, methods = ['GET', 'POST'])
  def hello_world():
      if request.method == 'POST':
          origin_hex_id = request.form['origin']
          destination_hex_id = request.form['destination']
          travelMode = request.form['mode']
          origin_coordinates = h3.h3_to_geo(origin_hex_id)
          destination_coordinates = h3.h3_to_geo(destination_hex_id)
          if (h3.h3_is_valid(origin_hex_id) and h3.h3_is_valid(destination_hex_id)):
              available = ETAcalculation.query.filter_by(origin = origin_hex_id, destination = destination_hex_id, mode = travelMode).first()
              reverse_available = ETAcalculation.query.filter_by(origin = destination_hex_id, destination = origin_hex_id, mode = travelMode).first()
              if available is None and reverse_available is not None:
                  return reverse_available.distance
              if available is not None and reverse_available is None:
                  return available.distance
              if available is None and reverse_available is None:
                  result_distance = int(haversine(origin_coordinates, destination_coordinates))
                  new_record = ETAcalculation(origin = origin_hex_id, destination = destination_hex_id, mode = travelMode, distance = result_distance)
                  return result_distance
                  try:
                      db.session.add(new_record)
                      db.session.commit()
                  except:
                      &quot;There was an error encountered in adding the details&quot;
      else:
          return render_template('index.html')
  
  
  if __name__ == &quot;__main__&quot;:
      app.run(debug=True)
  </code></pre>