Я использую Windows 10 (x64), Python 3.8, Django 3.0.5, QGIS3.10 после установки geo django и osgeo4w, когда я запускаю код, я мог получить доступ к карте (листовка ) и добавьте к нему маркер, но когда я пытаюсь увидеть отметку, которую я уже отметил, и ее название, я получил такую ошибку
django.contrib.gis.gdal.error.GDALException: OGR failure
Я пробовал смотреть на похожие вопросы, но ни одного решений сработали. кстати, Также я добавил в свои настройки проекта Django:
if os.name == 'nt':
import platform
OSGEO4W = r"C:\OSGeo4W"
if '64' in platform.architecture()[0]:
OSGEO4W += "64"
assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
os.environ['OSGEO4W_ROOT'] = OSGEO4W
os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
Полная трассировка:
Internal Server Error: /admin/firstproject/incidence/5/change/
Traceback (most recent call last):
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 145, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 143, in _get_response
response = response.render()
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\response.py", line 83, in rendered_content
return template.render(context, self._request)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader_tags.py", line 188, in render
return template.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 173, in render
return self._render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\defaulttags.py", line 309, in render
return nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\defaulttags.py", line 309, in render
return nodelist.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 992, in render
return render_value_in_context(output, context)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 971, in render_value_in_context
value = str(value)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\html.py", line 373, in <lambda>
klass.__str__ = lambda self: mark_safe(klass_str(self))
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\forms\boundfield.py", line 33, in __str__
return self.as_widget()
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\forms\boundfield.py", line 92, in as_widget
return widget.render(
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\forms\widgets.py", line 241, in render
context = self.get_context(name, value, attrs)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\leaflet\forms\widgets.py", line 78, in get_context
context = super(LeafletWidget, self).get_context(name, value, attrs)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\forms\widgets.py", line 67, in get_context
'serialized': self.serialize(value),
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\leaflet\forms\widgets.py", line 40, in serialize
return value.geojson if value else ''
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\geos\geometry.py", line 387, in json
return self.ogr.json
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\geos\geometry.py", line 429, in ogr
return gdal.OGRGeometry(self._ogr_ptr(), self.srs)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\geos\geometry.py", line 436, in srs
return gdal.SpatialReference(self.srid)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\gdal\srs.py", line 92, in __init__
self.import_epsg(srs_input)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\gdal\srs.py", line 277, in import_epsg
capi.from_epsg(self.ptr, epsg)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\gdal\prototypes\errcheck.py", line 117, in check_errcode
check_err(result, cpl=cpl)
File "C:\Users\M-ALMASRI\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\gis\gdal\error.py", line 59, in check_err
raise e(msg)
django.contrib.gis.gdal.error.GDALException: OGR failure.
[08/May/2020 04:40:46] "GET /admin/firstproject/incidence/5/change/ HTTP/1.1" 500 466508
Я также добавил свои модели models.py и admin.py для Location
models.py:
from django.db import models
from django.db.models import Manager as GeoManager
from django.contrib.gis.db import models
class Incidence (models.Model):
name =models.CharField(max_length=30)
location =models.PointField(srid=4326)
objects = GeoManager()
def __str__(self):
return self.name
Admin.py :
from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin
# Register your models here.
from .models import Incidence
class IncidenceAdmin(LeafletGeoAdmin):
pass
admin.site.register(Incidence,IncidenceAdmin)
setting.py:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': '****',
'USER': '****',
'HOST':'localhost',
'PASSWORD':'****',
'PORT':'5433'
},
}