【发布时间】:2019-12-20 02:29:54
【问题描述】:
client = MongoClient("mongodb:xxxx")
db = client.databasename
collection = db.logs
@app.route('/log')
def Results():
try:
loggings = db.collection.find()
return render_template('index.html', loggings=loggings)
except Exception as e:
return dumps({'error': str(e)})
if __name__ == '__main__':
app.run(debug = True)
这是我的 app.py 和 'index.html' 的代码,我的代码看起来像
<!doctype html>
<html>
<body>
{% for message in logs %}
<h3>{{message}}</h3>
{%endfor%}
</body>
</html>
当我运行代码时,它不会在 localhost:xxxx/log 路由上显示任何内容。
我可以知道为什么吗? 谢谢!
【问题讨论】:
-
您以
loggings=发送数据,因此在模板中您必须使用... in loggings,而不是...in log
标签: python mongodb logging flask