I'm trying to run Flask from an imported module (creating a wrapper using decorators).
Basically I have:
app.py:
import mywrapper
@mywrapper.entrypoint
def test():
print("HEYO!")
mywrapper.py
from flask import Flask
ENTRYPOINT = None
app = Flask(__name__)
@app.route("/")
def listen():
"""Start the model API service"""
ENTRYPOINT()
def entrypoint(f):
global ENTRYPOINT
ENTRYPOINT = f
return f
FLASK_APP=app
Running python -m flask, however, results in:
flask.cli.NoAppException: Failed to find Flask application or factory in module "app". Use "FLASK_APP=app:name to specify one.
Is there any trick to getting Flask to run like this? Or is it just not possible? The purpose of this is to abstract Flask away in this situation.
In my head flask should try to import mywrapper.py, which imports app.py which should generate the app and route, yet this doesn't seem to be what occurs.
Any help would be appreciated.
FLASK_APPenvironment variable as advised in the error message?appandapp.py. Specifying a factory isn't what I want, because the app is never actually generated inapp.py. Taking inspiration from another question that's appeared on the side, I have found that usingfrom mywrapper import *works. So this seems to be a case of Flask not detecting the app if it's not namespaced into the target run module. I want to find a way around this.app = mywrapper.appintoapp.pymakes this work... Is there no way around requiring this line?