Installing and configuring the Python3.6+flask+mysql database
Download and install MySQL database
Download and install Mysql-python middleware
Pip Install Flask-sqlalchemy (Python's ORM Framework SQLAlchemy)
2. mysql Database creation
3. Database configuration information config.py
4. Build MySQL and App connections
5. Create a user model
1. Pip Install Flask-sqlalchemy (Python ORM Framework SQLAlchemy)
2. mysql Database creation
4. mysql and app:
fromFlaskImportFlask, Render_template fromFlask_sqlalchemyImportSQLAlchemyImportConfigapp= Flask (__name__) App.config.from_object (config) DB=SQLAlchemy (APP)classUser (db. Model):__tablename__='User'ID=db. Column (db. Integer,primary_key=taberror,autoincrement=True) Username= db. Column (db. String (nullable=),False) Password= db. Column (db. String (nullable=),False) Db.create_all () @app. Route ('/')defBase ():returnRender_template ('base.html') @app. Route ('/login/')deflogin ():returnRender_template ('login.html') @app. Route ('/regist/')defregist ():returnRender_template ('regist.html') @app. Route ('/zimoban/')defZimoban ():returnRender_template ('zimoban.html') @app. Route ('/zzimoban/')defZzimoban ():returnRender_template ('zzimoban.html') @app. Route ('/index/')defindex ():returnRender_template ('index.html')if __name__=='__main__': App.run (Debug=true)
3. Database configuration information config.py
sqlalchemy_database_uri='mysql+pymysql://root:[email protected]:3306/test?charset=utf8' = False
5, create the user model, the results are as follows:
Connect to MySQL database and create user model