Connect to MySQL database and create user model

Source: Internet
Author: User
Tags mysql create mysql create database

    1. Installing and configuring the Python3.6+flask+mysql database
      1. Download and install MySQL database
      2. Download and install Mysql-python middleware
      3. Pip Install Flask-sqlalchemy (Python's ORM Framework SQLAlchemy)
    2. MySQL CREATE database
    3. Database configuration Information config.py
    4. Build MySQL and App connections
    5. 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

Related Article

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.