Search code examples
pythonflaskflask-restful

"TypeError: 'NoneType' object is not callable" using flask


I am using flask_api to build a simple web application, however I get a TypeError.

Here is my code:

user.py:

#!/usr/bin/env python
from flask.ext.api import FlaskAPI
from flask import request, url_for

class User_operations(object):

    def login_v(self):
        return 'hello'  

app.py:

#!/usr/bin/env python
from flask.ext.api import FlaskAPI
from user import User_operations

app = FlaskAPI(__name__)
bj = User_operations()

@app.route('/example/',methods=['GET', 'POST'])
def example():
    bj.login_v()

if __name__ == "__main__":
  app.run(debug=True)

This gives me the error:

"TypeError: 'NoneType' object is not callable"

Solution

  • In your view function example you are missing the return statement:

    @app.route('/example/',methods=['GET', 'POST'])
    def example():
      return bj.login_v()