Je veux commencer le gunicorn avec >> gunicorn wsgi:app
. Je reçois une erreur en disant ModuleNotFoundError: No module named 'default_config
. Mon env virtuel est activé. J'ai passé des heures sur google mais je n'ai pas trouvé de réponse. Même les indices sont très appréciés.Python ModuleNotFoundError pendant le lancement du gunicorn
Structure de dossier:
- App
- flask_app
- __init__.py
- factory.py
- default_config.py
- venv (virtual environment)
- wsgi.py
__init__.py
=> est vide
### wsgi.py ###
from flask_app.factory import create_app
app = create_app('development')
.
### default_config.py ###
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
SECRET_KEY = 'development key'
class DevelopmentConfig(Config):
DEBUG = True
class ProductionConfig(Config):
DEBUG = False
config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
}
.
### factory.py ###
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from default_config import config
db = SQLAlchemy()
def create_app(config_name):
app = Flask(__name__, instance_relative_config=True)
app.config.from_object(config[config_name])
app.config.from_pyfile('config.py')
db.init_app(app)
return app
convertir "de default_config import config" à "à partir de .default_config importer config" – mohammad
Cela a fonctionné! Peux-tu me dire pourquoi? Si vous soumettez une réponse, je peux la marquer comme acceptée. – Jan