我使用django-leaflet完成了我的传单程序,但地图没有在输出中显示任何内容
这是代码
models.py
from django.db import models
from django.contrib.gis.db import models as gismodels
class MushroomSpot(gismodels.Model):
title = models.CharField(max_length=256)
id1=models.IntegerField(primary_key=True)
geom = gismodels.PointField()
objects = gismodels.GeoManager()
def __unicode__(self):
return self.title
urls.py
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from djgeojson.views import GeoJSONLayerView
from .models import MushroomSpot
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),
url(r'^data.geojson$', GeoJSONLayerView.as_view(model=MushroomSpot), name='data'),
]
的index.html
{% load leaflet_tags %}
<html>
<head>
{% leaflet_js %}
{% leaflet_css %}
</head>
<body>
<h1>Weather Stations</h1>
{% leaflet_map "main" callback="main_map_init" %}
<script type="text/javascript">
function main_map_init (map, options) {
var dataurl = '{% url "data" %}';
// Download GeoJSON via Ajax
$.getJSON(dataurl, function (data) {
// Add GeoJSON layer
L.geoJson(data).addTo(map);
});
}
</script>
</body>
</html>
与settings.py
中的传单相关的内容DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR
LEAFLET_CONFIG = {
'DEFAULT_ZOOM': 6,
'MIN_ZOOM': 1,
'MAX_ZOOM': 20,
}
我运行了
的setup.py文件import csv
from django.contrib.gis.geos import Point
from mushrooms.models import MushroomSpot
csv_file = 'mycsv.csv'
def dms2dec(value):
"""
Degres Minutes Seconds to Decimal degres
"""
degres, minutes, seconds = value.split()
#seconds, direction = seconds[:-1], seconds[-1]
dec = float(degres) + float(minutes)/60 + float(seconds)/3600
#if direction in ('S', 'W'):
# return -dec
return dec
reader = csv.DictReader(open(csv_file), delimiter=",")
for line in reader:
lng = dms2dec(line.pop('mlong'))
lat = dms2dec(line.pop('mlat'))
wmoid = int(line.pop('id'))
name = line.pop('place').title()
print(lng,lat)
MushroomSpot(id1=wmoid, title=name, geom=Point(lng, lat)).save()
请帮助我在屏幕上获取输出地图 我不知道它的错误是什么 csv文件包含印度约8个城市的数据 我希望将所需的印度地图作为交互式网页地图 请让我达到我想要的输出