Monday, April 28, 2014

Re: IndentationError :Unexpected Indent

2014-04-28 7:55 GMT+02:00 Kelvin Mwangi <kschinoda@gmail.com>:
 I have been following up on the tutorial on Python version 1.6 and I got stuck at an indentation error I can't seem to debug. Its under the first tutorial of creating Django application and I modified my polls\models.py file to look like this;

from django.db import models
import datetime
from django.utils import timezone

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    def __unicode__(self):  
        return self.question
def was_published_recently (self):
return self.pub_date > = timezone.now() - datetime.timedelta(days=1)

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
def __unicode__(self):  
        return self.choice_text 

I keep getting an error at that line that starts with "def was_published_recently.." and can't seem to debug the error. Can anyone kindly help me here? I'm stuck. :( 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0e2ec62a-a7a5-4ebd-b639-975cc514e060%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

You have too many indentations. Make sure that def was_published_recently (self): starts on the same column as def __unicode__(self):

Python is very sensitive to indentations. As a rule of thumb read the pep 08 coding coventions (http://legacy.python.org/dev/peps/pep-0008/).

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUbk_hDQcY9SaubiUt1umWP5tEc2t%2BWz6uUngdMP1sVS2Cw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment