def init_app(app, extra_config_settings={}):
# Read common settings from 'app/settings.py'
app.config.from_object('app.settings')
# Read environment-specific settings from 'app/local_settings.py'
try:
app.config.from_object('app.local_settings')
except ImportError:
print("The configuration file 'app/local_settings.py' does not exist.\n"+
"Please copy app/local_settings_example.py to app/local_settings.py\n"+
"and customize its settings before you continue.")
exit()
# Add/overwrite extra settings from parameter 'extra_config_settings'
app.config.update(extra_config_settings)
if app.testing:
app.config['WTF_CSRF_ENABLED'] = False # Disable CSRF checks while testing
# Initialize Flask-SQLAlchemy and Flask-Script _after_ app.config has been read
#db.init_app(app)
# Setup Flask-Migrate
#migrate = Migrate(app, db)
#manager.add_command('db', MigrateCommand)
# Setup Flask-Mail
mail = Mail(app)
# Setup WTForms CsrfProtect
#CsrfProtect(app)
# Define bootstrap_is_hidden_field for flask-bootstrap's bootstrap_wtf.html
from wtforms.fields import HiddenField
def is_hidden_field_filter(field):
return isinstance(field, HiddenField)
app.jinja_env.globals['bootstrap_is_hidden_field'] = is_hidden_field_filter
# Setup an error-logger to send emails to app.config.ADMINS
init_email_error_handler(app)
# Setup Flask-User to handle user account related forms
#from app.models import User, MyRegisterForm
#from app.views import user_profile_page
#db_adapter = SQLAlchemyAdapter(db, User) # Setup the SQLAlchemy DB Adapter
#user_manager = UserManager(db_adapter, app, # Init Flask-User and bind to app
#register_form=MyRegisterForm, # using a custom register form with UserProfile fields
#user_profile_view_function=user_profile_page,
#)
#import app.manage_commands
评论列表
文章目录