在环境变量.flaskenv文件中如果不设置FLASK_ENV=development,运行flask run都是生产环境。设置了FLASK_CONFIG=development也不起效果,还是生产环境。
相关代码如下
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
:author: Chile
:url: xxx
:copyright: © 2019 Chile
:license: MIT, see LICENSE for more details.
"""
'a learn module'
__author__ = 'Chile'
import os
from flask import Flask
from bluelog.settings import config
#传入程序实例
from bluelog.extensions import bootstrap, db, mail, ckeditor, moment
# 导入蓝本
from bluelog.blueprints.blog import blog_bp
from bluelog.blueprints.admin import admin_bp
from bluelog.blueprints.auth import auth_bp
# Bluelog程序的工厂函数
def create_app(config_name=None):
if config_name is None:
# 优先从.env环境变量冲传入,没有的就传入第二参数值development
config_name = os.getenv('FLASK_CONFIG', 'development')
app = Flask('bluelog') # 实例化app
app.config.from_object(config[config_name])
# 工厂处理函数
register_logging(app) # 注册日志处理器
register_extensions(app) # 注册扩展(扩展初始化)
register_blueprints(app) # 注册蓝本
register_commands(app) # 注册自定义shell命令
register_errors(app) # 注册错误处理函数
register_shell_context(app) # 注册shell上下文处理函数
register_template_context(app) # 注册模板上下文处理函数
return app
def register_logging(app):
pass
def register_extensions(app):
# 完成初始化
bootstrap.init_app(app)
db.init_app(app)
mail.init_app(app)
ckeditor.init_app(app)
moment.init_app(app)
def register_blueprints(app):
# 蓝本注册程序实例
app.register_blueprint(blog_bp)
app.register_blueprint(admin_bp, url_prefix='/admin')
app.register_blueprint(auth_bp, url_prefix='/auth')
def register_shell_context(app):
@app.shell_context_processor
def make_shell_context():
return dict(db=db)
def register_template_context(app):
pass
def register_errors(app):
@app.errorhandler(400)
def bad_request(e):
return render_template('errors/400.html'), 400
def register_commands(app):
pass
在.flaskenv文件中设置截图如下
FLASK_APP=bluelog
FLASK_CONFIG=development
不知道以上是哪里出的问题。