Skip to content Skip to sidebar Skip to footer

Python Class Method Definition : "unexpected Indent"

I am getting started with Django and Python so naturally I'm doing the polls project tutorial. I am working under Windows 7 with Python 2.7.9 and Django 1.3.7 I have this piece of

Solution 1:

Your class header is in same indentation with its content , you need to refine the indentation (as a pythonic way use 4 space for indentation ):

classPoll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    def__unicode__(self):
        returnself.question

Solution 2:

Python works on proper indendation. Your code should be

class Poll(models.Model):
    question = models.CharField(max_length=200)//see these as part of class variable
    pub_date = models.DateTimeField('date published')
    def __unicode__(self): //part of class's operationreturnself.question

Post a Comment for "Python Class Method Definition : "unexpected Indent""