Django manage.py shell Throws error when meet "def"
Question: I am reading django official tutorial (
<http://docs.djangoproject.com/en/dev/intro/tutorial01/> ). When i try run
"python manage.py shell", python throw error:

    
    
    File "D:\DjangoProjects\mysite\polls\models.py", line 8
       def __unicode__(self):
       ^
    IndentationError: unexpected indent
    

Help please! How solve this problem?

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
    


Answer: You have a python indentation error. I'm not exactly sure where, but the
django docs show this:
<http://docs.djangoproject.com/en/dev/intro/tutorial01/>

So follow it to the letter /space.

    
    
    class Poll(models.Model):
        # ...
        def __unicode__(self):  
            return self.question
    

Your exact indentation you've pasted wouldn't throw that error, but in your
real code, you must have the `def __unicode__` line at the exact indent depth
as the other lines in your model.

Make sure you are using spaces and not tabs for all of your indents, as tabs
can sometimes make the indent level seem the same as the others.

