- 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)
- MySQL CREATE database
- Database configuration Information config.py
- Build MySQL and App connections
- Create a user model
config.py:
' Mysql+pymysql://root:@127.0.0.1:3306/qq?charset=utf8 ' = False
To establish a connection + create a model:
fromFlaskImportFlask 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 ('/')defHello_world ():return 'Hello world!'if __name__=='__main__': App.run ()
Connect to MySQL database and create user model