关于Flask Config文档
2019-03-07 本文已影响0人
Dozing
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
SQLALCHEMY_TRACK_MODIFICATIONS = False
MAIL_SERVER = 'smtp.126.com'
MAIL_PORT = 25
MAIL_USE_TLS = True
MAIL_USERNAME = json_dict['MAIL_USERNAME']
MAIL_PASSWORD = json_dict['MAIL_PASSWORD']
FLASK_MAIL_SUBJECT_PREFIX = '[FLASKY]'
FLASK_MAIL_SENDER = 'Flasky Admin ' + json_dict['EMAIL_ADDRESS']
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:" + json_dict['MAIL_PASSWORD'] + "@localhost:3306/robot"
config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
}
在用python flask编写网页,运行时候遇到以下的错误:
File "C:\Flask\config.py", line 26, in <module>
'testing': TestingConfig,
NameError: name 'TestingConfig' is not defined
为什么这里的'TestingConfig' is not defined说没有被定义。因为'TestingConfig'在这里是一个对象,是一个变量。Python是动态的,这里的对象和变量不能没有初始化或者定义!
这就是为什么config这个字典要放到在最后的原因!