【发布时间】:2015-02-24 14:42:10
【问题描述】:
在我的烧瓶应用程序中,前端和后端是分开的。如何每天在我设置的特定时间将 JSON 返回到前端。
例如
@api.route('/sda')
def Daily():
# Get all entries (all students from all courses) that match today's date in MMDDYYYY format
entries = Entry.query.filter_by(timestamp.strftime('%M%D%Y')=datetime.datetime.now().strftime('%M%D%Y')).all()
# Count how many students attend school today (Since in the entries array, there are duplicate student with same ID, and I only want to count it once per student)
# When the loop ends, it will return a jsonify with today's date and total number of students attend school today
JSON 文件中的预期数据:
{
"dsa": [
{
"date": "12252014",
"present": 470,
"absent": 30
},
{
"date": "12262014",
"present": 490,
"absent": 10
},
{
"date": "12272014",
"present": 400,
"absent": 100
}
}
因为我意识到每当前端访问路由/sda时,该函数每次都会返回jsonify,并将JSON文件中的值复制为相同的date。
【问题讨论】:
-
你到底想要什么?
标签: python json flask sqlalchemy