在开发和生产中一切都很好(使用wsgi的apache2.4),问题是在生产中找不到.env文件变量。他们都是空的!
这是.env文件
SQLALCHEMY_DATABASE_URI='sqlite:///fbl_utilities.db'
LOGS_PATH='C:/Apache2.4/flask-app-env/accessRequestBackend/app/logs/run-time-logs.log'
这是配置类为
的config.py文件import os
from dotenv import load_dotenv
load_dotenv()
class Config:
SECRET_KEY = os.getenv('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')
MAIL_SERVER = os.getenv('SMTP_HOST')
MAIL_PORT = os.getenv('SMTP_PORT')
MAIL_USE_TLS = os.getenv('SMTP_TLS')
MAIL_username = os.getenv('SMTP_USER')
MAIL_PASSWORD = os.getenv('SMTP_PASS')
LOGS_PATH = os.getenv('LOGS_PATH')
这是 init .py文件,正在启动我的应用
def create_app(config_class=Config):
# init
app = flask(__name__)
app.config.from_object(Config)
# dependancies
db.init_app(app)
bcrypt.init_app(app)
login_manager.init_app(app)
mail.init_app(app)
# routes
from app.users.routes import users
from app.main.routes import main
from app.departments.routes import departments
from app.requesttypes.routes import requesttypes
from app.serverapprovals.routes import serverapprovals
from app.serverrequestgroups.routes import serverrequestgroups
from app.serverrights.routes import serverrights
from app.servers.routes import servers
from app.vpnapprovals.routes import vpnapprovals
from app.vpns.routes import vpns
app.register_blueprint(users)
app.register_blueprint(main)
app.register_blueprint(departments)
app.register_blueprint(requesttypes)
app.register_blueprint(serverapprovals)
app.register_blueprint(serverrequestgroups)
app.register_blueprint(serverrights)
app.register_blueprint(servers)
app.register_blueprint(vpnapprovals)
app.register_blueprint(vpns)
return app
最后是我的.wsgi文件
import sys
sys.path.insert(0,'C:/Apache2.4/flask-app-env/accessRequestBackend')
from app import create_app
application = create_app()
我认为在apache + wsgi中为代码加载环境变量时,如果找不到 SQLALCHEMY_DATABASE_URI 的值,则缺少某些内容。所有其他变量都一样