1

Edit: I am able to resolve the spacing/tab issues by adjusting the settings in Sublime Text. I tried converting spaces to tabs as suggested in some answers, but it didn't work for me. Instead, converting indentations to spaces did.

View > Indentation > Convert Indentations to Spaces

I am new to Python/Django (doing the Tango with Django tutorial) and am having indentation errors. I've read and tried out some solutions regarding indentation errors, but nothing is working for me. Hope someone is able to help me out - thanks in advance!

manage.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tango_django.settings")

from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

error:

$ python manage.py makemigrations rango
File "manage.py", line 8
from django.core.management import execute_from_command_line
                                                           ^
IndentationError: unindent does not match any outer indentation level

I tried tabnanny and got this:

$ python -m tabnanny manage.py
'manage.py': Indentation Error: unindent does not match any outer indentation level (<tokenize>, line 8)
Gina
  • 13
  • 4
  • 2
    You should Tango with Python before you Tango with Django – César Nov 24 '15 at 20:40
  • 1
    Possible duplicate of [IndentationError: unindent does not match any outer indentation level](http://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – Daenyth Nov 24 '15 at 20:43
  • We all got to start somewhere right? – Gina Nov 24 '15 at 20:44
  • I am able to resolve these tabs/spaces problems in Sublime Text by "converting indentations to spaces" under the View settings. In the similar question, one user suggested "converting indentations to tabs" and that didn't do the trick for me. – Gina Nov 24 '15 at 20:49

1 Answers1

1

This is because there is no indented block below the if condition which ends with :. In Python, this is what we call significant whitespace.

Indent the content of the if block with 4 spaces for example which is PEP8 compliant:

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tango_django.settings")
jpic
  • 32,891
  • 5
  • 112
  • 113
  • Thanks @jpic for the quite response. I tried indenting 4 spaces per line, and now a new error pops up that seems related to the models.py. Luckily, I am able to resolve these tabs/spaces problems in Sublime Text by "converting indentations to spaces". – Gina Nov 24 '15 at 20:38
  • Maybe close this question and create a new one then ? – jpic Nov 24 '15 at 20:39