flask database

# Frame installation environment Flask_SQLALchemy, the mysqlclient 

from Flask Import the Flask
 from flask_sqlalchemy Import SQLAlchemy      # import database module 
App = the Flask ( the __name__ ) 
the app.config [ " SQLALCHEMY_DATABASE_URI " ] = ' MySQL: // the root: [email protected]/mysql '       # username and password database connected to the database host: MySQL 
DB = SQLAlchemy (App)                    # instantiates database 
@ app.route ( ' / ' )
 DEF index ():
     from SQLAlchemy Import text
    SLQ = text ( " the SELECT * the FROM 'the USER' " )                      # sql statement 
    the Result = db.engine.execute (sql)                          # execute sql statement to query 
    for Row in the Result: 
        app.logger.info (Row)                                 # log print out the query results 
    return  " database testing " 
IF  __name__ == " __main__ " : 
    app.run (Host = " 0.0.0.0 " , Debug = Ture)

 

Guess you like

Origin www.cnblogs.com/jum-bolg/p/10993985.html