一个条目包含:标题、链接、时间、文本。如何显示从 python 到 html 的所有条目?我尝试了很多选项,但找不到正确的语法。最后一次尝试:
应用程序.py:
from flask import Flask, render_template, jsonify
from flask_pymongo import PyMongo
app = Flask(__name__)
app.config["MONGO_URI"] = "mongodb+srv://..."
mongo = PyMongo(app)
@app.route('/', methods=['GET'])
def index():
link = mongo.db.archive.find({"link"})
title = mongo.db.archive.find({"title"})
text = mongo.db.archive.find({"text"})
time = mongo.db.archive.find({"time"})
return render_template('index.html', title=title, link=link, time=time, text=text)
if __name__ == "__main__":
app.run(debug=True)
HTML
<ul>
{% for title in titles %}
<li>
<label>
<span> TITLE: {{title}} <br> HREF: {{link}} <br> DATE: {{time_date}} <br> TEXT: {{text_stat}} </span>
</label>
</li>
{% endfor %}
</ul>