Forums

ImportError with flask app

I changed the structure of my flask app to utilize modules. The app works locally, but not sure why its running into a problem here.

WSGI file:

project_home = u'/home/leapfrog/citest'
if project_home not in sys.path:
sys.path = [project_home] + sys.path
from manage import app as application

manage.py

import os
from app import create_app, db
from app.models import *
from flask.ext.script import Manager, Shell

app = create_app('production')
manager = Manager(app)

def make_shell_context():
    return dict(app=app, db=db, User=User, UserDoc=UserDoc, Person=Person,
                ContactInfo=ContactInfo, Position=Position, PositionDoc=PositionDoc,
                Rep=Rep, School=School, SchoolDoc=SchoolDoc, TeacherDoc=TeacherDoc)
manager.add_command("shell", Shell(make_context=make_shell_context))

if __name__ == '__main__':
    manager.run()

Error log

2015-03-11 15:30:32,456 :Traceback (most recent call last):
2015-03-11 15:30:32,456 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-03-11 15:30:32,456 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-03-11 15:30:32,456 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-03-11 15:30:32,457 :    self.error(msg, *args, **kwargs)
2015-03-11 15:30:32,457 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-03-11 15:30:32,457 :    self._log(ERROR, msg, args, **kwargs)
2015-03-11 15:30:32,457 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-03-11 15:30:32,457 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-03-11 15:30:32,457 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-03-11 15:30:32,458 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-03-11 15:30:32,458 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-03-11 15:30:32,458 :    self.threadName = threading.current_thread().name
2015-03-11 15:30:32,458 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-03-11 15:30:32,458 :    return _active[_get_ident()]
2015-03-11 15:30:32,458 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-03-11 15:30:32,458 :    app_iterator = self.app(environ, start_response)
2015-03-11 15:30:32,459 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-03-11 15:30:32,459 :    raise e
2015-03-11 15:30:32,459 :ImportError: cannot import name manage

When the app is loaded I see the default "Hello from Flask!" on the homepage. Not sure how that is getting loaded or if adds any clues...

Can I take a look at your files on the disk? (We can see them from our side, but we always ask permission first.)

Yes, that would be great. Thanks

Hmm, your manage.py file in /home/leapfrog/citest looks like this:

# A very simple Flask Hello World app for you to get started with...

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello from Flask!'

That doesn't sound like it's what you'd expect...?

Wow, sorry for wasting your time. I'll make the adjustment and see if that works.

No problem :-) Let us know how you get on.