我正在尝试关注GeoDjango tutorial,但我无法创建模型。我是Python的初学者,使用Django 1.7,Python 2.7和Ubuntu 12.04。我做得很好,直到我必须使用python manage.py shell输入以下代码才能创建模型。
class WorldBorder(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()
mpoly = models.MultiPolygonField()
objects = models.GeoManager()
def __str__(self):
return self.name
我很确定我应该使用python manage.py shell,但是教程还不清楚。这是我从这样做的错误信息,
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-3-7541d9798060> in <module>()
----> 1 class WorldBorder(models.Model):
2 name = models.CharField(max_length=50)
3 area = models.IntegerField()
4 pop2005 = models.IntegerField('Population 2005')
5 fips = models.CharField('FIPS Code', max_length=2)
/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in __new__(cls, name, bases, attrs)
114 except ValueError:
115 app_label_index = 1
--> 116 kwargs = {"app_label": package_components[app_label_index]}
117
118 else:
IndexError: list index out of range
我唯一能看到错误的是settings.py。以下是我从默认设置中更改的内容。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'ravi',
'USER': 'ravi',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}
}
和
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'world'
)
我还需要在settings.py中更改其他内容吗?
此外,我发现的最接近我的问题的是this我尝试使用元标记(如旧教程的旧版本),如下所示:
class Meta:
verbose_name_plural = "World Borders"
这似乎没有任何改变。感谢所有帮助。
[1]: https://docs.djangoproject.com/en/dev/ref/contrib/gis/tutorial/