Skip to main content
 首页 » 编程设计

python之django-leaflet + django-geojson : I can't place a marker in Admin (TypeError: L. drawLocal.draw.toolbar.finish 未定义)

2025年02月15日29jirigala

这可能是微不足道的,但我找不到错误。我只是按照 GitHub 上的文档完成初始设置。我开始了一个新的应用程序。已安装 django-leaflet和 django-geojson , 创建了一个最小的 models.py 和 admin.py。

当我尝试通过管理员在 map 上放置标记时。没有任何反应,左侧用于绘制标记和多边形的图标丢失了。

我一定是缺少依赖项,忘记了一些琐碎的事情。但我已经一遍又一遍地阅读文档,我一定是看瞎了自己。

我还没有创建 View 或模板。只有模型和管理员。并迁移了数据库。


这是来自 Chrome 和 Firefox 的控制台日志。

Chrome

spritesheet.svg Failed to load resource: the server responded with a status of 404 (Not Found) 
leaflet.draw.js:9 Uncaught TypeError: Cannot read property 'title' of undefined 
    at e.getActions (leaflet.draw.js:9) 
    at e._createActions (leaflet.draw.js:9) 
    at e._showActionsToolbar (leaflet.draw.js:9) 
    at e._handlerActivated (leaflet.draw.js:9) 
    at e.fireEvent (leaflet.js:6) 
    at enable (leaflet.draw.js:8) 
    at HTMLAnchorElement.s [as _leaflet_click33] (leaflet.js:8) 

Firefox

10:34:46.995 TypeError: L.drawLocal.draw.toolbar.finish is undefined 1 leaflet.draw.js:9:15973 
 
    L.DrawToolbar<.getActions        http://127.0.0.1:8000/static/leaflet/draw/leaflet.draw.js:9:15973 
    L.Toolbar<._createActions        http://127.0.0.1:8000/static/leaflet/draw/leaflet.draw.js:9:12001 
    L.Toolbar<._showActionsToolbar   http://127.0.0.1:8000/static/leaflet/draw/leaflet.draw.js:9:12614 
    L.Toolbar<._handlerActivated     http://127.0.0.1:8000/static/leaflet/draw/leaflet.draw.js:9:11700 
    o.Evented<.fire                  http://127.0.0.1:8000/static/leaflet/leaflet.js:5:4955 
    L.Draw.Feature<.enable           http://127.0.0.1:8000/static/leaflet/draw/leaflet.draw.js:8:1810 
    o.DomEvent._on/h                 http://127.0.0.1:8000/static/leaflet/leaflet.js:6:11671 

安装包

appdirs==1.4.0 
Django==1.10.5 
django-geojson==2.9.1 
django-leaflet==0.20.0 
jsonfield==1.0.3 
olefile==0.44 
packaging==16.8 
Pillow==4.0.0 
psycopg2==2.6.2 
pyparsing==2.1.10 
six==1.10.0 

geodjango/settings.py

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django.contrib.gis', 
    'leaflet', 
    'djgeojson', 
    'djangomap', 
] 

djangomap/models.py

from django.db import models 
from djgeojson.fields import PointField 
 
class MapMarker(models.Model): 
    geom = PointField() 

djangomap/admin.py

from django.contrib import admin 
from leaflet.admin import LeafletGeoAdmin 
 
from djangomap.models import MapMarker 
 
admin.site.register(MapMarker, LeafletGeoAdmin) 

请您参考如下方法:

django-leaflet 0.20.0 需要 leaflet.draw 0.4 但提供 0.3。 解决此问题的拉取请求在这里 https://github.com/makinacorpus/django-leaflet/pull/179但到2017年2月28日仍未合并合并。

在合并之前,解决方法是: pip 卸载 django-leaflet pip 安装 django-leaflet-cadasta