使用Flask的以下路径从MongoDB中提取:
@app.route('/search-all/', methods=['GET', 'POST']) # EDIT
def search_all():
for x in db['mongo-moviedb'].find({"Films.Title" : "Clue"}, {"Films.$": 1}):
result = x
return render_template('Date-Night.html', result=result)
返回以下内容:
{'Films': [{'Actors': 'Eileen Brennan, Tim Curry, Madeline Kahn',
'Awards': 'N/A',
'BoxOffice': '$14,643,997',
'Country': 'United States',
'DVD': '27 Jun 2000',
'Director': 'Jonathan Lynn',
'Genre': 'Comedy, Crime, Mystery',
'Language': 'English, French',
'Metascore': '39',
'Plot': 'Six guests are anonymously invited to a strange mansion '
'for dinner, but after their host is killed, they must '
'cooperate with the staff to identify the murderer as the '
'bodies pile up.',
'Poster': 'https://m.media-amazon.com/images/M/MV5BM2VlNTE1ZmMtOTAyNS00ODYwLWFmY2MtZWEzOTE2YjE1NDE2XkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_SX300.jpg',
'Production': 'N/A',
'Rated': 'PG',
'Ratings': [{'Source': 'Internet Movie Database',
'Value': '7.2/10'},
{'Source': 'Rotten Tomatoes', 'Value': '68%'},
{'Source': 'Metacritic', 'Value': '39/100'}],
'Released': '13 Dec 1985',
'Response': 'True',
'Runtime': '94 min',
'Title': 'Clue',
'Type': 'movie',
'Website': 'N/A',
'Writer': 'John Landis, Jonathan Lynn, Anthony E. Pratt',
'Year': '1985',
'imdbID': 'tt0088930',
'imdbRating': '7.2',
'imdbVotes': '96,112'}],
'_id': ObjectId('638135b01687bf075645b0da')}
我不明白的是如何访问嵌套的Films
列表,以获取特定的项(Title
、Year
等)并将其加载到单独的变量(x
、y
、z
)中。
我试过x['Films']
,x['Films.Title']
,x['Films'],['Title']
,但我不确定我在这里要找什么。谢谢,伙计们。
1条答案
按热度按时间l0oc07j21#
x["Films"]
是一个只有一个值的列表,因此: