我已经使用 django-leaflet 完成了传单程序,但地图没有在输出中显示任何内容
这是代码
模型.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
网址.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'),
]
索引.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 个城市的数据我想要所需的印度地图作为交互式网络地图 请让我获得所需的输出