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
    
已邀请:
你有一个python缩进错误。我不确定在哪里,但是django文档显示了这个:http://docs.djangoproject.com/en/dev/intro/tutorial01/ 所以按照它来到字母/空格。
class Poll(models.Model):
    # ...
    def __unicode__(self):  
        return self.question
您粘贴的确切缩进不会引发该错误,但在您的实际代码中,您必须在精确缩进深度处使用
def __unicode__
线作为模型中的其他行。 确保使用空格而不是所有缩进的制表符,因为制表符有时会使缩进级别与其他缩进级别相同。     

要回复问题请先登录注册