0
我找到了一個簡寫的方法來從MongoDb中獲取結果並傳遞給jinja模板。Flask jinja正確顯示日期字段
@app.route('/home')
def home():
table = mongo.db.posts
result = table.find({ }).sort([("postdate", 1)])
records = json.loads(json_util.dumps(result))
if result.count() > 0:
return render_template('users/index.html', posts=records)
else:
message = 'I couldn't find any post'
return render_template('users/index.html', message=message)
而且在用戶/ index.html的我想顯示的結果是這樣的:
{% for post in posts %}
<tr>
<td>{{post._id}}</td>
<td>{{post.title}}</td>
<td>{{post.author}}</td>
<td class="date">{{post.postdate}}</td>
</tr>
{% endfor %}
一切正常,除了日期字段。有沒有辦法正確顯示日期字段?
{'$date': 1508227970796}
{'$date': 1508228089163}
{'$date': 1508241780398}