Попытка перебрать базу данных mon go db. Я думаю, что сделал, но что-то упустил, в базе данных есть две записи (фильмы), но, кажется, он находит одну и перебирает «подразделы» этого mov ie. То, что я хочу отобразить на странице html, - это плакат для каждого mov ie. У меня отображается один mov ie, но когда я распечатываю, какие данные он извлек, он печатает только один mov ie.
FLASK
@app.route('/', methods=['GET', 'POST'])
def homepage():
try:
for data in mongo.db.test.find():
return render_template("main.html", data = data)
except Exception as e:
return render_template("500.html", e = e)
HTML
<div id="output">
<p>{{ data }}</p>
{% for d in data %}
<a href="/movies/{% print(data['Title']) %}/"><img class="img-fluid inline-block"src="/static/images/{% print(data['filename']) %}" style="width:200px; height:300px" alt="Images don't appear to be loading?">
</a>
{% endfor %}
</div>
Данные Mongodb:
{
"Language": "English",
"ReleaseDate": "26 April 2019",
"StoryLine": "Avengers: Endgame picks up after the events of Avengers: Infinity War, which saw the Avengers divided and defeated. Thanos won the day and used the Infinity Stones to snap away half of all life in the universe. Only the original Avengers - Iron Man, Captain America, Thor, Hulk, Black Widow, and Hawkeye remain, along with some key allies like War Machine, Ant-Man, Rocket Raccoon, Nebula, and Captain Marvel. Each of the survivors deals with the fallout from Thanos' decimation in different ways, but when an opportunity presents itself to potentially save those who vanished, they all come together and set out to defeat Thanos, once and for all.",
"Title": "Avenger: Endgame",
"age": "PG-13",
"cast": ["Robert Downey Jr", "Chris Evans", "Mark Ruffalo", "Chris Hemsworth", "Scarlett Johansson", "Jeremy Renner", "Don Cheadle", "Paul Rudd", "\tBenedict Cumberbatch"],
"character": ["Tony Stark / Iron Man", "Steve Rogers / Captain America", "Bruce Banner / Hulk", "Thor", "Natasha Romanoff / Black Widow", "\tClint Barton / Hawkeye", "James Rhodes / War Machine", "\tScott Lang / Ant-Man", "Doctor Strange"],
"filename": "avngersendgameposter.jpg",
"genre": ["Action", "Adventure", "Sci-Fi"],
"keywords": ["Avenger", "EndGame"]
}
{
"Language": "English",
"ReleaseDate": "9 June 2006",
"StoryLine": "A hot-shot race-car named Lightning McQueen gets waylaid in Radiator Springs, where he finds the true meaning of friendship and family.",
"Title": "Cars",
"Trailer": "https://www.youtube.com/embed/SbXIj2T-_uk?rel=0",
"cast": ["Owen Wilson", "someoneelse"],
"character": ["Lightning McQueen", "Mator"],
"filename": "carsPoster.jpg",
"reviews": [{
"comment": "This is such a good movie.",
"header": "Pure Joy"
}, {
"comment": "This is such a good movie.",
"header": "Great."
}]
}
{
"Language": "English",
"ReleaseDate": "21 August 1987",
"StoryLine": "In 1963, Frances \"Baby\" Houseman, a sweet daddy's girl, goes with her family to a resort in upstate New York's Catskill Mountains. Baby has grown up in privileged surroundings and all expect her to go on to college, join the Peace Corps and save the world before marrying a doctor, just like her father. Unexpectedly, Baby becomes infatuated with the camp's dance instructor, Johnny Castle, a man whose background is vastly different from her own. Baby lies to her father to get money to pay for an illegal abortion for Johnny's dance partner. She then fills in as Johnny's dance partner and it is as he is teaching her the dance routine that they fall in love. It all comes apart when Johnny's friend falls seriously ill after her abortion and Baby gets her father, who saves the girl's life. He then learns what Baby has been up to, who with and worse, that he funded the illegal abortion. He bans his daughter from any further association with \"those people\". In the first deliberately willful action of her life, Baby later sneaks out to see Johnny, ostensibly to apologize for her father's rudeness, and ends up consummating her relationship with Johnny. A jealous fellow vacationer sees Baby sneaking out of Johnny's bungalow the next morning, and in an act of retribution, tells management that he is responsible for a theft the evening before, knowing he would not furnish his real whereabouts.",
"Title": "Dirty Dancing",
"age": "PG-13",
"cast": ["Jennifer Grey", " Patrick Swayze", " Jerry Orbach", " Cynthia Rhodes", " Jack Weston", " Jane Brucker"],
"character": ["Baby Houseman", "Johnny Castle", "Jake Houseman", "Penny Johnson", "\tMax Kellerman", "Lisa Houseman"],
"filename": "dirtydanceposter.jpg",
"genre": ["Drama", "Music", "Romance"],
"keywords": ["Dirty", " Dancing", " Dance"]
}
ВЫХОД: Вывод тока
Ожидаемый результат, все три разных плаката (только один раз)