我有代码可以找到并打印最近的医院:
python
@app.route('/check', methods=['POST'])
def check():
place = 'Checking nearest hospitals..'
API_KEY = 'MY_KEY'
google_places = GooglePlaces(API_KEY)
query_result = google_places.nearby_search(
lat_lng ={'lat': 40.4222532, 'lng': 49.8035278},
radius = 5000,
types =[types.TYPE_HOSPITAL])
if query_result.has_attributions:
print (query_result.html_attributions)
for place in query_result.places:
print(place.name)
return render_template('check.html', place=place.name)default.html
<form action="/check" method="POST">
<button type="check" class="btn btn-primary">Nearest Hospitals</button>
</form>hospital.html
<div class="box">
<p>{{ place.name }}</p>
</div>问题是,在我的html框中只能看到一家医院,但在控制台中有许多医院的打印。如何像控制台一样打印方框中的每个医院?
发布于 2020-05-11 03:50:53
您需要发送整个查询,而不仅仅是一个地名
python:
return render_template('hospital.html', places=query_result.places)您可以在循环中全部打印它们
hospital.html
<div class="box">
{% for place in places %}
<p>{{ place.name }}</p>
{% endfor %}
</div>https://stackoverflow.com/questions/61717750
复制相似问题