Django manage.py shell遇到“def”时出错。
我正在阅读django官方教程(http://docs.djangoproject.com/en/dev/intro/tutorial01/)。当我尝试运行“python manage.py shell”时,python throw错误:
File "D:DjangoProjectsmysitepollsmodels.py", line 8
def __unicode__(self):
^
IndentationError: unexpected indent
请帮忙!怎么解决这个问题?
models.py:
import datetime
from django.db import models
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
没有找到相关结果
已邀请:
1 个回复
鲁釜头
您粘贴的确切缩进不会引发该错误,但在您的实际代码中,您必须在精确缩进深度处使用
线作为模型中的其他行。 确保使用空格而不是所有缩进的制表符,因为制表符有时会使缩进级别与其他缩进级别相同。