简体   繁体   English

Flask PyMongo HTML 显示读取数据

[英]Flask PyMongo HTML show Read Data

I'm with my teams are currently working on some project face recognition presence system for COVID-19 anticipation, so people don't have to touch unnecessary things in the factory.我和我的团队目前正在开发一些用于 COVID-19 预期的人脸识别存在系统项目,因此人们不必在工厂触摸不必要的东西。

Right now, i am trying to show the data absence (for HRD / absence administrator access only) from my team's mongoDB atlas.现在,我正在尝试从我团队的 mongoDB 地图集中显示数据缺失(仅限 HRD / 缺席管理员访问)。 My HTML is loaded but it seems it's only load blank data.我的 HTML 已加载,但似乎只加载空白数据。

this is my app.route /database on app.py这是我在 app.py 上的app.py /database

@app.route("/database", methods=['GET', 'POST'])
def database():
    if not session.get('email'):
        return redirect(url_for('login'))

    elif request.method == 'POST':
        dataCollection = mongo.db.Presence_Data_Table.find()
        data = []
        for i in dataCollection:
            data.append()

    return render_template('database.html')

and this is my database.html这是我的database.html

The relevant code:相关代码:

<body>
    <div class="head-title">
       <h1>Admin Sign up</h1> 
    </div>
    <table>
    {% for i in dataCollection %}
    <tr>
        <td>
            <span>{{ i['Nama'] }}</span>
        </td>
        <td>
            <span>{{ i['Tanggal'] }}</span>
        </td>
        <td>
            <span>{{ i['Waktu'] }}</span>
        </td>
        <td>
            <span>{{ i['Activity'] }}</span>
        </td>
    </tr>
    {% endfor %}
    </table>
</body>
</html>

Any idea what's wrong with it?知道有什么问题吗? I'm sorry, i'm still newbie in flask development对不起,我还是 flask 开发的新手

Here what it's show up on my browser: https://i.imgur.com/uMVYc59.jpg这是我的浏览器上显示的内容: https://i.imgur.com/uMVYc59.jpg

And here's what's inside dataCollection https://i.imgur.com/zkMSFmZ.jpg这就是 dataCollection https://i.imgur.com/zkMSFmZ.jpg里面的内容

In your code above you are using the variable dataCollection, however as mentioned in the comments by ngShravil.py.在上面的代码中,您使用了变量 dataCollection,但是正如 ngShravil.py 的评论中所提到的。 You do not pass the variable from your back end web server to your browser.您不会将变量从后端 web 服务器传递到浏览器。

You need to modify the following lines:您需要修改以下几行:

return render_template('database.html')

to this:对此:

return render_template('database.html',data=data)

and then in your.html file do this:然后在您的.html 文件中执行以下操作:

{% for i in data%}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM