- 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
fromflask Import Flaskimport config fromflask_sqlalchemy Import Sqlalchemyapp=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) Nickname= db. Column (db. String ( -) ) Db.create_all () @app. Route ('/') def hello_world ():return 'Hello world!'if__name__ = ='__main__': App.run ()
config.py
' Mysql+pymysql://root:@127.0.0.1:3306/mis_db?charset=utf8 ' = False
Connect to MySQL database and create user model