title: Flask: TypeError: 'int' object is not callable
body: <p>I'm new to Python and just learning it as I work on this project, and this issue is really confusing me. Here's my code:</p>
  
  <pre><code>from flask import Flask
  from datetime import datetime
  
  # Setup app
  app = Flask(__name__)
  
  # Initialize data dict
  data = {}
  
  # Pretty-formats a time difference
  def formatdifference(delta):
      seconds = delta.total_seconds()
      if (seconds &lt; 60):
          return "{seconds} seconds ago" % {"seconds": seconds}
  
      return "{minutes} minutes ago" % {"minutes": seconds/60}
  
  # Sets a device battery level
  @app.route("/set/&lt;device&gt;/&lt;int:battery&gt;")
  def set(device, battery):
      data[device] = (battery, datetime.now())
      return "done"
  
  # Get's a device battery level
  @app.route("/get/&lt;device&gt;")
  def get(device):
      if not device in data:
          return "No heartbeats"
  
      devicedata = data[device]
      delta = datetime.now() - devicedata[1]
  
      if (delta.total_seconds() &gt; 10):
          return "Last heartbeat {diff}" % {"diff": formatdifference(delta)}
  
      return devicedata[0]
  
  if __name__ == "__main__":
      app.run(debug=True, host='0.0.0.0')
  </code></pre>
  
  <p>I call <code>/set/phone/40</code>. All good so far. Then I call <code>/get/phone</code>. Not so good. Here's the traceback:</p>
  
  <pre><code>TypeError: 'int' object is not callable
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
      return self.wsgi_app(environ, start_response)
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
      response = self.make_response(self.handle_exception(e))
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
      response = self.full_dispatch_request()
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
      response = self.make_response(rv)
    File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1577, in make_response
      rv = self.response_class.force_type(rv, request.environ)
    File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 825, in force_type
      response = BaseResponse(*_run_wsgi_app(response, environ))
    File "/usr/local/lib/python2.7/dist-packages/werkzeug/test.py", line 855, in run_wsgi_app
      app_iter = app(environ, start_response)
  TypeError: 'int' object is not callable
  </code></pre>
  
  <p>Using flask's debugger, I can see that in the last frame, app appears to be 40!</p>
  
  <p><img src="https://i.stack.imgur.com/fMu4f.png" alt=""></p>
  
  <p>How on earth did this happen, and how can I solve it?</p>