I've found a shorthand method to fetch the results from MongoDb and to pass to the jinja template.
@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)
And in users/index.html I would like to display the results like this:
{% 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 %}
Everything works as expected except date fields. Is there a way to display date fields correctly ?
{'$date': 1508227970796}
{'$date': 1508228089163}
{'$date': 1508241780398}