- 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
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=true,autoincrement=True) Username=db. Column (db. String (nullable=),False) Password=db. Column (db. String (nullable=),False) Db.create_all () @app. Route ('/')defindex ():returnRender_template ("index.html") @app. Route ('/login')deflogin ():returnRender_template ("login.html") @app. Route ('/regis')defRegister ():returnRender_template ("zhuce.html") @app. Route ('/fankui')defFankui ():returnRender_template ("page_help.html")if __name__=='__main__': App.run (Debug=true)
Config
' Mysql+pymysql://root:@127.0.0.1:3306/mis_db?charset=utf8 ' = False
Connect to MySQL database and create user model