Connect to MySQL database and create user model

Source: Internet
Author: User

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)

2. mysql Database creation

3. Database configuration information config.py

4. Build MySQL and App connections

5. Create a user model

1. Pip Install Flask-sqlalchemy (Python ORM Framework SQLAlchemy)

2. mysql Database creation

4. mysql and app:

 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=taberror,autoincrement=True) Username= db. Column (db. String (nullable=),False) Password= db. Column (db. String (nullable=),False) Db.create_all () @app. Route ('/')defBase ():returnRender_template ('base.html') @app. Route ('/login/')deflogin ():returnRender_template ('login.html') @app. Route ('/regist/')defregist ():returnRender_template ('regist.html') @app. Route ('/zimoban/')defZimoban ():returnRender_template ('zimoban.html') @app. Route ('/zzimoban/')defZzimoban ():returnRender_template ('zzimoban.html') @app. Route ('/index/')defindex ():returnRender_template ('index.html')if __name__=='__main__': App.run (Debug=true)

3. Database configuration information config.py

sqlalchemy_database_uri='mysql+pymysql://root:[email protected]:3306/test?charset=utf8'   = False

5, create the user model, the results are as follows:

Connect to MySQL database and create user model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.