Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask and passenger "TypeError: 'module' object is not callable"

I'm trying to run flask on a server with passenger. This is my passenger_wsgi.py file:

import sys, os
INTERP = os.path.join(os.environ['HOME'], 'flask_env', 'bin', 'python')
if sys.executable != INTERP:
    os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.getcwd())

from wtf import app as application

# Uncomment next two lines to enable debugging
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(application, evalex=True)

There is an app.py file under wtf folder. There is also __init__.py in there so python recognizes it as a module directory. However it gives me this error:

Traceback (most recent call last)
File "/home/hiepha19/flask_env/lib/python2.6/site-packages/werkzeug/debug/__init__.py", line 88, in debug_application
app_iter = self.app(environ, start_response)
TypeError: 'module' object is not callable
like image 618
Hieu Phan Avatar asked Feb 22 '14 00:02

Hieu Phan


1 Answers

When you import app you are importing the app module (which most likely has an app name inside it which points to your Flask app. What you want to do is import that name and register it:

from wtf.app import app as application
# Note the extra app

It is worth noting that you do not need to do this manually - simply run Flask using the run method on the app and pass the argument debug=True to get the same behavior:

from wtf.app import app

if __name__ == '__main__':
    app.run(debug=True)
like image 66
Sean Vieira Avatar answered Oct 15 '22 22:10

Sean Vieira