M
M
MeinJun2020-06-06 21:36:26
MongoDB
MeinJun, 2020-06-06 21:36:26

How to output all records from mongo db to flask?

How to display all records from the database to the web using flask?
My code outputs only one, where instead of text, these are the things:
5edbe22134a71551672293.jpeg
My attempts in Flask:

from flask import Flask, render_template
from pymongo import MongoClient

app = Flask(__name__)

client = MongoClient("mongodb+srv://")
db = client.database
collection = db.archive


@app.route('/')
def index():
""" Пробововал подключать и Flask-pymongo меняя на команды из документации, толку особого не дало"""
    title = collection.find()
    link = collection.find()
    time = collection.find()
    text = collection.find()
    return render_template('index.html', title=title, link=link, time=time, text=text)

if __name__ == "__main__":
    app.run(debug=True)

But even if you fix it, it will display only one entry, but how to display all?
On the node, it was possible to create as many records in html using {{Each + const from the c .find({})}} route as in the database, but how in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2020-06-06
@Viji

It's like
https://stackoverflow.com/questions/45558349/flask...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question