【发布时间】:2014-10-14 22:33:48
【问题描述】:
这是我目前遇到的问题:
- 我正在使用命令提示符在 Windows 上运行 the first django tutorial
- 我在 models.py 中创建了一个名为“问题”的表。
- 我正在尝试在此类中创建
__str__()函数,如下所示:
.
from django.db import models
class Question(models.Model):
def __str__(self):
return self.question_text`
这就是我的 models.py 的样子:
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
我收到的错误如下:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 117, in __new__
kwargs = {"app_label": package_components[app_label_index]}
IndexError: list index out of range
有人知道吗?我是 django 的菜鸟,我不能 100% 确定 base.py 应该在这里做什么。
Base.py 可以在这里找到:https://github.com/django/django/blob/master/django/db/models/base.py
【问题讨论】:
标签: python django django-models