Flask 前端分页与下载
Flask 前端分页与下载
1 | {% if goods.has_prev %} |
1 |
|
下载判断
@page.route(“/goodsdown”)
def download():
goodslist = Goods.query.all()
data = []
for goods in goodslist:
temp = {}
temp[“id”] = goods.id
temp[“name”] = goods.name
temp[“price”] = goods.price
temp[“img”] = goods.img
data.append(temp)
# 每次下载 向数据库中写入count
count = Count.query.first()
print("count", count)
if not count:
count = Count(count=1)
db.session.add(count)
db.session.commit()
else:
count.count += 1
db.session.commit()
with open("static/data.json", "w") as f:
jstr = json.dumps(data, ensure_ascii=False)
f.write(jstr)
return send_file("static/data.json", as_attachment=True, cache_timeout=1)