from models import WorldBorder ImportError: No module named 'models'
from models import WorldBorder ImportError: No module named 'models'
为什么它显示错误我按照设置 GeoDjango 教程一切正确,为什么数据不会加载
型号Class:
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官网的教程有什么问题
在 load.py 中,更改此行:
from models import WorldBorder # shoudn't it be WorldBorders with an s?
至:
# Assuming your appname is called 'world' and your
# WorldBorders class is in world/models.py
from world.models import WorldBorders
上面的行可能会根据您的应用程序名称而改变。如果您的应用程序名称是 "world",那么它应该可以工作。如果您的应用程序名称是 "ApplicationName",则执行此操作:
from ApplicationName.models import WorldBorders
编辑:根据您的文件结构,我认为您的应用程序可能被称为 "geodjango" 所以也许可以尝试:
from geodjango.models import WorldBorders
为什么它显示错误我按照设置 GeoDjango 教程一切正确,为什么数据不会加载
型号Class:
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官网的教程有什么问题
在 load.py 中,更改此行:
from models import WorldBorder # shoudn't it be WorldBorders with an s?
至:
# Assuming your appname is called 'world' and your
# WorldBorders class is in world/models.py
from world.models import WorldBorders
上面的行可能会根据您的应用程序名称而改变。如果您的应用程序名称是 "world",那么它应该可以工作。如果您的应用程序名称是 "ApplicationName",则执行此操作:
from ApplicationName.models import WorldBorders
编辑:根据您的文件结构,我认为您的应用程序可能被称为 "geodjango" 所以也许可以尝试:
from geodjango.models import WorldBorders