flask - NameError: name 'app' is not defined

You are using the app before importing it, here lm.init_app(app), app is not defined yet.

It should look like this:

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
import os

from flask.ext.login import LoginManager
from flask.ext.openid import OpenID
from config import basedir

app = Flask(__name__)
app.config.from_object('config')

lm= LoginManager()
lm.init_app(app)
oid = OpenID(app,os.path.join(basedir,'tmp'))
lm.login_view = 'login'

db = SQLAlchemy(app)

from app import views, models

This error is because of you are not defining app and directly using app

Solution is add this line in your code : app Flask(__name__)

Example: app.py

from flask import Flask
#You need to use following line [app Flask(__name__]
app = Flask(__name__)
@app.route('/')
def index():
    return "Hello World with flask"
if __name__ == '__main__':
    app.run(port=5000,debug=True)

Tags:

Python

Flask