Of course, my Flask application works in my development environment but not on the server. Here are the relevant files:
|- application
|---- __init__.py
|---- config.py
|---- ...
|- wsgi.py
|- .env
Here's wsgi.py
from application import init_app
app = init_app()
if __name__ == "__main__":
app.run("host=0.0.0.0)
Here's application/__init__.py
from flask import Flask
def init_app():
# Initialize the core application
app = Flask(__name__, instance_relative_config=True)
# Select and load config object dynamically based on the value of FLASK_ENV in .env
if app.config["ENV"] == "production":
app.config.from_object("application.config.ProductionConfig")
else:
app.config.from_object("application.config.DevelopmentConfig")
with app.app_context():
return app
And finally .env
FLASK_APP=application
FLASK_ENV=development
I have verified that on my development machine, changing the value of FLASK_ENV in .env
works as expected. On the server, it tries running as production regardless of the value. What am I missing?
Edit to add that this is an Ubuntu 20 server on AWS Lightsail if that's important.