我正在从PostgreSQL读取数据,以获取纬度,经度和jpeg文件名称的数据集。我正在遍历数据集以在地图上创建标记。我没有收到错误消息,但是地图没有显示。
我正在index.html页面上显示数据。我正在使用iframe来显示map.html。我已经阅读了许多有关该主题的主题,但是没有一个答案对我有用。
views.py:
from django.shortcuts import render
from django.http import HttpResponse
from .models import PhotoInfo
import folium
# Create your views here.
def index(request):
VarPhotoInfo = PhotoInfo.objects.order_by('DateTaken')
context = {'PhotoInfo': VarPhotoInfo }
return render(request,'natureapp/index.html',context)
def show_map(request):
PhotoInfo1 = PhotoInfo.objects.order_by('DateTaken')
m = folium.Map([33.571345, -117.763265], zoom_start=10)
test = folium.Html('<b>Hello world</b>', script=True)
popup = folium.Popup(test, max_width=2650)
folium.RegularPolygonMarker(location=[33.571345, -117.763265], popup=popup).add_to(m)
fg = folium.FeatureGroup(name = "MyMap")
for i in PhotoInfo1:
fg.add_child(folium.Marker(location=(float(i.Lat),float(i.Long)),popup = str(i.DateTaken) +' file: '+ i.PhotoName, icon = folium.Icon(color='green')))
m.add_child(fg)
m.get_root().render()
context = {'MyMap': m}
return render(request, 'natureapp/map.html', context)
map.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>NatureMapper</title>
</head>
<h1>Map goes here </h1>
{{ my_map.render }}
</html>
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>NatureMapper</title>
</head>
<h1>Here it is! </h1>
{% if PhotoInfo %}
{% for Photo in PhotoInfo %}
<p>there is info.</p>
<p> {{ Photo.PhotoName }}</p>
<p> {{ Photo.Lat }}</p>
<p> {{ Photo.Long }}</p>
<p> <img src="{{ Photo.PhotoImage.url }}" width = "240" alt=""></p>
{% endfor %}
{% else %}
<p>there is no info.</p>
{% endif %}
<iframe id="encoder_iframe" height=95% width="70%" src="{% url 'show_map' %}">
</iframe>
</html>
Index.html正确显示数据。 Map.html只是显示“地图在这里”标题。没有错误消息。