In the Flask project, establish a models.py in the configuration database as follows:
1 #-*-coding:utf-8-*-2 ImportOS3 fromFlaskImportFlask4 fromItsdangerousImportTimedjsonwebsignatureserializer as Serializer5 fromFlaskImportCurrent_app6 from.ImportDB7 fromFlask_sqlalchemyImportSQLAlchemy8 fromWerkzeug.securityImportGenerate_password_hash, Check_password_hash9 fromFlask_loginImportusermixinTen fromFlask_loginImportlogin_required One fromFlask_momentImportmoment A fromFlask_bootstrapImportBootstrap - from.ImportLogin_manager - theBasedir = Os.path.abspath (Os.path.dirname (__file__)) - -App = Flask (__name__) - #Configuration Data +app.config['Secret_key'] ='stong Key' -app.config['Sqlalchemy_database_uri'] ='Mysql://root:[email Protected]:3306/flask' +app.config['Sqlalchemy_commit_teardown'] =True ABootstrap =Bootstrap (APP) atmoment =Moment (APP) -db =SQLAlchemy (APP) - -App.run (Debug=true)
Learn the challenges of using the Flask-sqlalchemy management database with the Python Flask+django web framework