AttributeError: 'NoneType' object has no attribute 'route' (app not created)
AttributeError: None route
$ flask run
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'route'
Why this happens
If app is None due to failed initialization or incorrect ordering (using @app.route before assigning app), decorators will attempt to call route on None.
Fix
- Create the app first, then declare routes.
- For factories, don’t decorate at import time; register routes inside
create_app().
Wrong code
@app.route('/')
def index():
return 'OK'
from flask import Flask
app = Flask(__name__)
Fixed code
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'OK'