django期待一个缩进的块

时间:2015-04-14 09:22:07

标签: django

我在第71行收到错误

class UserProfile(AbstractBaseUser):
name            = models.CharField(max_length=25)
email           = models.EmailField(max_length=75)
is_active       = models.BooleanField(default=True)
is_admin        = models.BooleanField(default=False)

objects = MyUserManager()

USERNAME_FIELD  = 'email'
REQUIRED_FIELDS = ['name']

def get_full_name(self):
    # The user is identified by their email address
    return self.email //line error

def get_short_name(self):
    # The user is identified by their email address
    return self.email

def __str__(self):              # __unicode__ on Python 2
    return self.email

@property
def is_staff(self):
    "Is the user a member of staff?"
    # Simplest possible answer: All admins are staff
    return self.is_admin

这是错误,预期"返回"

中的缩进块
 return self.email

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

您可能误认为标签和空格,或者之前在行中有一个额外的空格。

重新执行函数的标识,分析其余代码是否使用空格或制表符。

答案 1 :(得分:0)

整个类定义必须缩进,如下所示:

class UserProfile(AbstractBaseUser):
    name            = models.CharField(max_length=25)
    email           = models.EmailField(max_length=75)
    is_active       = models.BooleanField(default=True)
    is_admin        = models.BooleanField(default=False)

    objects = MyUserManager()

    USERNAME_FIELD  = 'email'
    REQUIRED_FIELDS = ['name']

    def get_full_name(self):
        # The user is identified by their email address
        return self.email //line error

    def get_short_name(self):
        # The user is identified by their email address
        return self.email

    def __str__(self):              # __unicode__ on Python 2
        return self.email

    @property
    def is_staff(self):
        "Is the user a member of staff?"
        # Simplest possible answer: All admins are staff
        return self.is_admin