It's not a Django thing.  It is a python thing.

Python, as you probably know, determines statement nesting by the amount
that the line is indented, that is, the width of the whitespace between the
beginning of the line and the first non-whitespace character.

The error message says that it has found a line that is indented less than
the (most recent non-empty, non-comment) line before it, and the amount
that it is indented is not the same as any line before it since the most
recent line that is indented less than it is.

Basically, python  can't tell which block the statement is part of.

You must nest all statements that are part of the same block by exactly the
same amount.

    if some_condition:
        a = b
      b = 3

In the above code the b = 3 line would trigger this exception.  The a = b
line defines the indentation level for the block controlled by the if (8
spaces).  So is the b = 3 line supposed to be in the if block or not?  If
it were indented 8 spaces, it would be controlled by the condition.  If it
were indented 4 spaces, like the if, it would be after the end of the if
block, that is, it would be executed regardless of the condition.  But it
is indented 6 spaces, and python objects.

A common problem leading to errors like this is using an editor you are not
familiar with, or one that is not correctly configured for editing python
(such as making a "quick change" on the server using vi or vim).  This
occurs because of varying treatment of the TAB key, and of TAB characters
in the file.  My editors are all configured to insert enough spaces to get
to the next multiple of 4, the indentation step that I like) when I press
the TAB key, at least when they are editing a file with extension ".py".
If there are and TAB characters in the file, they display that as taking
you to the next multiple of 8 columns, because that is how python
interprets them, unless you jump through some small hoops to tell it
otherwise (bad idea if there is any possibility that someone else will ever
edit or read your file).  (8 is the tradition default ASCII tab stop from
the 1960s, if not longer.)  Sadly, many modern editors (including modern
default configurations of vi and vim) have taken to believing that tabstops
occur every 4 columns, and that they can achieve them with TAB characters,
rather than the equivalent number of spaces.

So if the "if" statement in the code above were indented using a TAB
character, and the editor displayed that as going the fourth column, and
the a = b line were indented with two TAB characters, being displayed as
going to the eighth column, and the b = 3 line were indented with one TAB
character and four spaces, it would appear to be indented exactly the same
as the a = b line.  But python, by default, would interpret the "if" as
being indented by 8 columns, the a = b line by 16 columns, and the b = 3
line by 12 columns, and you would see the kind of indentation error you are
getting for the b = 3 line, despite the fact that it "looks right" in your
editor.

So configure your python editors to always convert TAB characters in files
to the corresponding number of spaces (either when read or when written),
to always display TAB characters as taking you to the next multiple of 8
columns, and to interpret the TAB key as meaning to insert spaces only to
take you to your favorite indentation step (I suggest 4 columns, but tastes
vary).  (vim can certainly be configured like this, emacs's python mode is
like this by default, and any programing editor that knows about python
should  do this too.  The editor built into idle, which comes with windows
python, and can be installed on other systems, does this as well, but it's
a wimpy editor.)  That way if you ever have to edit your file on an
unfamiliar editor, it will look right, and if you avoid the TAB key and
manually insert or remove the correct number of spaces, things will
continue to work.

Bill

On Thu, Mar 7, 2013 at 9:06 AM, frocco <faro...@gmail.com> wrote:

> I do not understand what the error indentation means.
> I am new to django, coming from PHP.
> I was using touch, because unlike PHP, I wanted changes to show without
> kicking users off.
> now I am afraid to use touch.
>
>
> On Thursday, March 7, 2013 8:54:15 AM UTC-5, Roberto López López wrote:
>
>>
>> Check the history of the files you've touched, and rollback all
>> indentation changes.
>>
>>
>>
>> On 03/07/2013 02:49 PM, frocco wrote:
>> > Hello,
>> >
>> > I am not sure what happened, I did a touch wsgi and then a touch
>> wsgi.py
>> > I got an error afterwards and could not recover from it. I could not
>> > find the views.py it was complaining about.
>> > I tried to reload the site from a backup and still had errors. I ended
>> > up recreating the site on webfaction and uploading each app until it
>> was
>> > working.
>> >
>> >
>> >   IndentationError at /
>> >
>> > unindent does not match any outer indentation level (views.py, line 29)
>> >
>> > Django Version:        1.5
>> > Exception Type:        IndentationError
>> > Exception Value:
>> >
>> > unindent does not match any outer indentation level (views.py, line 29)
>> >
>> > Exception Location:
>> > /home/frocco/webapps/ntw/lib/**python2.7/django/utils/**importlib.py
>> in
>> > import_module, line 35
>> > Python Executable:        /usr/local/**bin/python
>> > Python Version:        2.7.3
>> > Python Path:
>> >
>> > ['/home/frocco/webapps/ntw',
>> >  '/home/frocco/webapps/ntw/**myproject',
>> >  '/home/frocco/webapps/ntw/**lib/python2.7',
>> >  '/home/frocco/lib/python2.7/**pip-1.2.1-py2.7.egg',
>> >  '/home/frocco/lib/python2.7',
>> >  '/usr/local/lib/python27.zip'**,
>> >  '/usr/local/lib/python2.7',
>> >  '/usr/local/lib/python2.7/**plat-linux2',
>> >  '/usr/local/lib/python2.7/**lib-tk',
>> >  '/usr/local/lib/python2.7/**lib-old',
>> >  '/usr/local/lib/python2.7/**lib-dynload',
>> >  '/usr/local/lib/python2.7/**site-packages',
>> >  '/usr/local/lib/python2.7/**site-packages/PIL']
>> >
>> > --
>> > 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...@**googlegroups.com.
>> > To post to this group, send email to django...@googlegroups.com.
>> > Visit this group at 
>> > http://groups.google.com/**group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>.
>>
>> > For more options, visit 
>> > https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>.
>>
>> >
>> >
>>
>>
>> --
>> Kind regards,
>>
>> Roberto L�pez L�pez
>>
>>
>> System Developer
>> Parallab, Uni Computing
>> H�yteknologisenteret, Thorm�hlensgate 55
>> N-5008 Bergen, Norway
>> Tel:        (+47) 555 84091
>>
>  --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to