0
爲什麼它顯示的錯誤,我跟着來設置GeoDjango內置教程一切是正確的,所以數據不會加載從模型導入WorldBorder導入錯誤:沒有名爲模塊「模型」
模型類:
from django.contrib.gis.db import models
class WorldBorders(models.Model):
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2)
iso2 = models.CharField('2 Digit ISO', max_length=2)
iso3 = models.CharField('3 Digit ISO', max_length=3)
un = models.IntegerField('United Nations Code')
region = models.IntegerField('Region Code')
subregion = models.IntegerField('Sub-Region Code')
lon = models.FloatField()
lat = models.FloatField()
# GeoDjango-specific: a geometry field (MultiPolygonField), and
# overriding the default manager with a GeoManager instance.
mpoly = models.MultiPolygonField()
objects = models.GeoManager()
class Meta:
verbose_name_plural = "World Borders"
# Returns the string representation of the model.
def __unicode__(self):
return self.name
Load.py
import os
from django.contrib.gis.utils import LayerMapping
from models import WorldBorder
world_mapping = {
'fips' : 'FIPS',
'iso2' : 'ISO2',
'iso3' : 'ISO3',
'un' : 'UN',
'name' : 'NAME',
'area' : 'AREA',
'pop2005' : 'POP2005',
'region' : 'REGION',
'subregion' : 'SUBREGION',
'lon' : 'LON',
'lat' : 'LAT',
'mpoly' : 'MULTIPOLYGON',
}
world_shp = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'TM_WORLD_BORDERS-0.3.shp'))
def run(verbose=True):
lm = LayerMapping(Pakistan, world_shp, world_mapping,transform=False, encoding='utf8')
lm.save(strict=True, verbose=verbose)
錯誤加載數據
from world import load
Traceback (most recent call last):
File "/Users/Ismail/mainFolder/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 69, in handle
self.run_shell(shell=options['interface'])
File "/Users/Ismail/mainFolder/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 61, in run_shell
raise ImportError
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/Ismail/mainFolder/geodjango/world/load.py", line 3, in <module>
from models import WorldBorder
ImportError: No module named 'models'
>>>
什麼是錯在Django網站的教程
是, WorldBorder類在world/models.py中,而load.py也在同一個目錄中,我已經改變了,但是它不能工作相同的錯誤。 from world.models import WorldBorder –
@JonasDavid你應該導入WorldBorders(用s),因爲模型有s。當你試圖用s(即來自world.models import WorldBorders)做它時它工作嗎? – user2719875
@JonasDavid還有,你的應用程序名稱是什麼? (進入settings.py並查看安裝的應用程序)。你是否只有一個應用程序,並且該應用程序是否被稱爲世界? – user2719875