0
MongoDb에서 결과를 가져 와서 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 %}
모든 작동합니다. 날짜 필드를 올바르게 표시하는 방법이 있습니까? 배열을 보내기 전에
당신이 읽을 수있는 형식으로 날짜를 변환하는 당신 안에이보기를 사용 CA :
{'$date': 1508227970796}
{'$date': 1508228089163}
{'$date': 1508241780398}