Forums

Webapp - Import problem: No module found

I guess I'm the 1000th person asking this question, but since I'm a newbie I can't find the way the solve it. I'm having this error:

 ImportError: cannot import name 'app' from 'project'

init.py:

# init.py
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager

db = SQLAlchemy()

def create_app():
    app = Flask(__name__)

    ....

    return app

wsgi:

if project_home not in sys.path:
    sys.path = [project_home] + sys.path

# import flask app but need to call it "application" for WSGI to work
from project import app as application  # noqa

I'm sure it's some dumb mistake but can't understand what I'm missing.

Solved. I edited the wsgi file from:

from project import app as application  # noqa

to:

from project import create_app  # noqa
application = create_app()

Great!