- 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
1 fromFlaskImportFlask, Render_template2 fromFlask_sqlalchemyImportSQLAlchemy3 ImportConfig4 5App = Flask (__name__)6 app.config.from_object (config)7db=SQLAlchemy (APP)8 9 classUser (db. Model):Ten __tablename__='User' OneID = db. Column (db. Integer,primary_key=true,autoincrement=True) AUsername=db. Column (db. String (nullable=),False) -Password=db. Column (db. String (nullable=),False) - the Db.create_all () - -@app. Route ('/') - defindex (): + returnRender_template ('index.html') - +@app. Route ('/login/') A deflogin (): at returnRender_template ('login.html') - -@app. Route ('/regist/') - defRegister (): - returnRender_template ('regist.html') - in@app. Route ('/base/') - defBase (): to returnRender_template ('base.html') + -@app. Route ('/question/') the defquestion (): * returnRender_template ('question.html') $ Panax Notoginseng if __name__=='__main__': -App.run ()
congfig.py
sqlalchemy_database_uri='mysql+pymysql://root:[email protected]:3306/ni_db?charset=utf8' = False
Connect to MySQL database and create user model