flask连接Mysql数据库
时间:2022-08-01 来源:未知 投稿:admin 点击:次
例:
from flask import Flask,render_template from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) HOSTNAME = '58.218.204.78' PORT = '3306' DATABASE = 'fwqzx_com' USERNAME = 'fwqzx_com' PASSWORD = '123456' DB_URI = 'mysql+pymysql://{}:{}@{}:{}/{}?charset-utf8'.format(USERNAME,PASSWORD,HOSTNAME,PORT,DATABASE) app.config['SQLALCHEMY_DATABASE_URI'] = DB_URI app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True db = SQLAlchemy(app) @app.route("/") def index(): engine = db.get_engine() conn = engine.connect() resule = conn.execute("SELECT 1") print(resule.fetchone()) return "hello" if __name__ == "__main__": app.run(port=80)
如果您的问题仍未解决,还可以加入服务器在线技术交流QQ群:8017413寻求帮助。
相关内容