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

1

7

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
Tertian answered 22/2, 2014 at 0:34 Comment(0)
S
14

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)
Sasha answered 22/2, 2014 at 2:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.