I have a Flask app (python 3.7) that runs perfectly fine using Flask run command, its build using the factory pattern. However, I would like to run it with a production optimized wsgi server, running on windows/linux.
However, when I try to run this using waitress:
waitress-serve --host 127.0.0.1 --call 'ws:create_app'
I end up with the following error:
There was an exception (ModuleNotFoundError) importing your module.
It had these arguments:
1. No module named 'ws.models'
the project structure looks as follows:
|_ws
|_ __init__.py
|_ commands.py
|_ config.py
|_ helper_schemas.py
|_ router.py
|_ models
|_ __init__.py
|_ user.py
|_ event.py
|_ analytics.py
|_ whisky.py
|_ api
|_ __init__.py
|_V1
|_ __init__.py
|_ user.py
|_ event.py
my main ws -> __init__.py file looks like this:
import sentry_sdk
from flask import Flask, session
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from flask_restful import Api
from flask_cors import CORS
from .config import *
from flask_migrate import Migrate
db = SQLAlchemy()
ma = Marshmallow()
api = Api()
def create_app():
app = Flask('__name__')
CORS(
app,
origins=['http://localhost:8100', 'http://localhost:8101', ],
supports_credentials=True
)
# env_config = os.getenv("APP_SETTINGS", "config.DevelopmentConfig")
configuration = Config
if app.debug:
configuration = DevelopmentConfig
else:
print("[APP] Running production!")
configuration = ProductionConfig
app.config.from_object(configuration)
db.init_app(app)
ma.init_app(app)
from . import router
app.register_blueprint(router.bp)
with app.app_context():
from .api import V1
app.register_blueprint(V1.api_bp)
from . import commands
app.cli.add_command(commands.tools_cli)
app.secret_key = configuration.SECRET_KEY
SESSION_TYPE = configuration.SESSION_TYPE
Migrate(app, db)
@app.before_request
def before_request():
session.permanent = True
return app
from .models.user import *
from .models.analytics import *
from .models.event import *
from .models.whisky import *
each of the files under models does a from ws import db and for the ones under api its from ws import ma, db
I have tried a LOT of things and searched everywhere but I cannot seem to get rid of the error. Any ideas?