hand
_1_1_23
4
python3.X - Web - Flask1.1.1
共46篇
python3.X - Web - Flask1.1.1
返回栏目
0k
0.3k
1k
6k
0.6k
0.8k
0.3k
0.1k
0.2k
0.8k
0.6k
0.6k
0.1k
0.5k
0.2k
2k
0.3k
5k
2k
2k
1k
0.3k
1k
0.1k
1k
1k
0.5k
2k
2k
0.7k
1k
2k
0.1k
1k
0.1k
2k
2k
0.9k
5k
4k
1k
1k
3k
1k
0k
0k
返回python3.X - Web - Flask1.1.1栏目
作者:
贺及楼
成为作者
更新日期:2021-11-07 11:20:50
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from _datetime import datetime
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:@127.0.0.1:3306/XXXXXX数据库名XXXXXX?charset=utf8mb4"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app)
#数据库-Wechatdatabase表-用户
class Wechatdatabase(db.Model):
__tablename__ = 'wechat_user001'
id = db.Column(db.Integer,primary_key=True)
openid = db.Column(db.VARCHAR(255))
nickname = db.Column(db.VARCHAR(255))
sex = db.Column(db.Integer)
province = db.Column(db.Text)
city = db.Column(db.Text)
country = db.Column(db.Text)
unionid = db.Column(db.VARCHAR(255))#微信uid
points = db.Column(db.Integer)#现在拥有的点数
success_points = db.Column(db.Integer)#成功充值点数
success_times = db.Column(db.Integer)#成功充值次数
success_total_fee = db.Column(db.Integer)#成功充值金额
orders = db.relationship('Wechatdatabaseorder',backref='nickname2')#这个用户的订单集合
def __repr__(self):
return 'Wechatdatabase:OK'
#数据库-Wechatdatabaseorder表-订单
class Wechatdatabaseorder(db.Model):
__tablename__ = 'wechat_user_orders001'
id = db.Column(db.Integer,primary_key=True)#订单id
openid = db.Column(db.VARCHAR(255))
nickname = db.Column(db.VARCHAR(255))
unionid = db.Column(db.VARCHAR(255))
out_trade_no = db.Column(db.VARCHAR(255))#订单号
order_name = db.Column(db.VARCHAR(255))#订单名
state = db.Column(db.VARCHAR(255))#订单状态未付款,已付款
creat_time = db.Column(db.DateTime, default=datetime.now)#创建时间
time_end = db.Column(db.VARCHAR(14))
update_time = db.Column(db.DateTime, default=datetime.now,onupdate=datetime.now)#更新时间
total_fee = db.Column(db.Integer)#订单价格
spbill_create_ip = db.Column(db.VARCHAR(64))
Wechatdatabase_id = db.Column(db.Integer,db.ForeignKey('wechat_user001.id'))#这个系统的下单的人id
def __repr__(self):
return 'Wechatdatabaseorder: ok'
#db.drop_all() #谨慎开
db.create_all() # 创建当前应用中声明的所有模型类对应的数据表,db.drop_all()是删除表
@app.route("/")
def index():
return "hello"
if __name__ == '__main__':
app.run(debug=True)
python3.X - Web - Flask1.1.1
整章节共46节
快分享给你的小伙伴吧 ~