30 lines
792 B
Python
30 lines
792 B
Python
|
|
from flask import Flask,url_for
|
||
|
|
from imooc import route_imooc
|
||
|
|
from flask_sqlalchemy import SQLAlchemy
|
||
|
|
app = Flask(__name__) # 创建1个Flask实例
|
||
|
|
app.register_blueprint(route_imooc,url_prefix = "/imooc")
|
||
|
|
|
||
|
|
|
||
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@127.0.0.1/food_db'
|
||
|
|
db = SQLAlchemy(app)
|
||
|
|
@app.route("/")
|
||
|
|
def Hello_world():
|
||
|
|
|
||
|
|
url = url_for("index")
|
||
|
|
# url_1=UrlManager.buildUrl("/api")
|
||
|
|
return "Hello World,"+url
|
||
|
|
|
||
|
|
@app.route("/api")
|
||
|
|
def index():
|
||
|
|
return 'Index page'
|
||
|
|
|
||
|
|
@app.route("/api/hello")
|
||
|
|
def hello():
|
||
|
|
from sqlalchemy import text
|
||
|
|
sql = text("SELECT * FROM `user`")
|
||
|
|
result = db.engine.execute(sql)
|
||
|
|
for row in result:
|
||
|
|
app.logger.info(row)
|
||
|
|
return 'hello word page'
|
||
|
|
if __name__ == '__main__':
|
||
|
|
app.run(host='0.0.0.0',debug=True)
|