- 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
Sqlalchemy_database_uri='mysql+pymysql://root:[email Protected]:3306/mis14?charset=utf8 '= False
fromFlask Import Flask fromflask_sqlalchemy Import Sqlalchemyimport Configapp=Flask (__name__) app.config.from_object (config) DB=SQLAlchemy (APP) classUser(db. Model): __tablename__= 'User'ID=Db.Column(Db.Integer, Primary_key=True,autoincrement=True) Username=Db.Column(Db. String ( -), Nullable=False) Password=Db.Column(Db. String ( -), Nullable=False) Db.create_all ()@app. Route ('/') def hello_world ():return 'Hello world!'if__name__== '__main__': App.run ()
Connect to MySQL database and create user model