Inconsistent dedent error

1,062 views
Skip to first unread message

Gary Roach

unread,
Jun 23, 2016, 3:22:39 PM6/23/16
to Django users
Hi all,

The following code is part of the djangoproject.com/en/1.9/tutorial part
2 in mysite/polls/models.py

class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def __str__(self):
return self.question_text


class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)

def _str__(self):
return self.choice_text

The last entry (def __str__(self): throws an error "inconsistent dedent
at line .... I can find nothing wrong. I have tried retyping the line
with no results. I'm using Eclipse IDE with PyDev plugin. This is not
just an annoyance. Any attempt to do migrate errors out with the same
error. The code is typed verbatim from the tutorial.

I am at a loss as how to fix this . Please help.

Gary R.

Erik Cederstrand

unread,
Jun 23, 2016, 5:42:03 PM6/23/16
to Django Users

> Den 23. jun. 2016 kl. 21.21 skrev Gary Roach <gary71...@verizon.net>:
>
> class Choice(models.Model):
> question = models.ForeignKey(Question, on_delete=models.CASCADE)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField(default=0)
>
> def _str__(self):
> return self.choice_text
>
> The last entry (def __str__(self): throws an error "inconsistent dedent at line .... I can find nothing wrong.

The error is actually in the line above. Your field definitions are 7-space indented when they should only be 3- or 4-space indented.

Python requires you to have consistent indenting, preferably 4 spaces per every indentation level. Your editor should help you with that. See https://www.python.org/dev/peps/pep-0008/#indentation

Erik

Gary Roach

unread,
Jun 23, 2016, 6:34:20 PM6/23/16
to django...@googlegroups.com
Thanks,

Another pair of eyes never hurts.

Gary R.

Reply all
Reply to author
Forward
0 new messages