Sqolalchemy_database_url='mysql+pymsql://root:[email protected]:3306/mis_db?charset=utf8' = False
fromFlaskImportFlask fromFlaskImportrender_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=taberror,autoincrement=True) Username=db. Column (db. String (nullable=),False) Password= db. Column (db. String (nullable=),False) Db.create_all () @app. Route ('/')defswitch ():returnRender_template ('switch.html') @app. Route ('/login/')deflogin ():returnRender_template ('login.html') @app. Route ('/register/')defRegister ():returnRender_template ('register.html') @app. Route ('/wenda/')defWenda ():returnRender_template ('wenda.html')if __name__=='__main__': App.run (Debug=true)
Connect to MySQL database and create user model