【发布时间】:2021-04-04 10:35:27
【问题描述】:
我已经安装了 django、postgresql、postgis、Qgis 和 GDAL
这样的地图显示。
地图上无任何显示
如何解决 geoDjango 问题?
在models.py:
from django.contrib.gis.db import models
class Shop(models.Model):
name = models.CharField(max_length=200)
location = models.PointField()
address = models.CharField(max_length=200)
city = models.CharField(max_length=50)
在setting.py:
INSTALLED_APPS = [
'django.contrib.gis', # geo,
'geoshops', # user apps
]
try:
import gdal
gdal_path = Path(gdal.__file__)
OSGEO4W = os.path.join(gdal_path.parent, 'osgeo')
os.environ["OSGEO4W_ROOT"] = OSGEO4W
os.environ["GDAL_DATA"] = os.path.join(OSGEO4W, "data", "gdal")
os.environ["PROJ_LIB"] = os.path.join(OSGEO4W, "data", "proj")
os.environ["PATH"] = OSGEO4W + ";" + os.environ["PATH"]
GEOS_LIBRARY_PATH = str(os.path.join(OSGEO4W, "geos_c.dll"))
GDAL_LIBRARY_PATH = str(os.path.join(OSGEO4W, "gdal301.dll"))
except ImportError:
GEOS_LIBRARY_PATH = None
GDAL_LIBRARY_PATH = None
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']
【问题讨论】:
-
看起来
location字段的小部件已加载,但地图的实际图块并未加载。你能分享你如何在管理员中注册你的模型吗?还值得检查浏览器控制台中是否有任何 JS 错误。 -
@rootart。没有 JS 错误。 # 将“Shop”模型注册到管理员 ===> admin.site.register(Shop)
-
您可以尝试使用
OSMGeoAdmin类和自定义ShopAdmin并使用它进一步注册模型。 ``` 类 ShopAdmin(OSMGeoAdmin): 传递 admin.site.register(Shop, ShopAdmin) ```
标签: python django postgresql postgis qgis