Re: Stuck

36 views
Skip to first unread message

Jonathan

unread,
Dec 26, 2012, 2:41:21 PM12/26/12
to django...@googlegroups.com
The stack trace you pasted clearly indicates that you have an indentation error in your polls/models.py module. It appears that you've applied two spaces to the 'votes' field while 'poll' and 'choice' have four. If you'll apply four spaces to all the field, the interpreter won't complain.

On 12/26/2012 12:22 PM, rktu...@gmail.com wrote:
I'll keep this as short as possible. When I input  python manage.py sql polls, i get the following error:
 
C:\Python27\Lib\site-packages\django\bin\mysite>python manage.py sql pol
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py
443, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py
382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", l
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", l
 in execute
    self.validate()
  File "C:\Python27\lib\site-packages\django\core\management\base.py", l
 in validate
    num_errors = get_validation_errors(s, app)
  File "C:\Python27\lib\site-packages\django\core\management\validation.
e 30, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "C:\Python27\lib\site-packages\django\db\models\loading.py", line
 get_app_errors
    self._populate()
  File "C:\Python27\lib\site-packages\django\db\models\loading.py", line
_populate
    self.load_app(app_name, True)
  File "C:\Python27\lib\site-packages\django\db\models\loading.py", line
load_app
    models = import_module('.models', app_name)
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 3
port_module
    __import__(name)
  File "C:\Python27\Lib\site-packages\django\bin\mysite\polls\models.py"
0
    votes = models.IntergerField()
                                 ^
IndentationError: unindent does not match any outer indentation level

So here is my settings.py "Installed apps" 

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
'polls',
)

And here is my models.py:

from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
    votes = models.IntergerField()

I am running python 2.7 and Django 1.4.3 on Windows 8
Thanks!!!!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/e7XydlWTUVgJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Gabriel [SGT]

unread,
Dec 26, 2012, 2:41:42 PM12/26/12
to django...@googlegroups.com
On Wed, Dec 26, 2012 at 4:22 PM, <rktu...@gmail.com> wrote:
> IndentationError: unindent does not match any outer indentation level

The error is quite self explanatory.

Nick Dokos

unread,
Dec 26, 2012, 2:45:51 PM12/26/12
to django...@googlegroups.com
> IndentationError: unindent does not match any outer indentation level
>
> So here is my settings.py "Installed apps"
>
> INSTALLED_APPS = (
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.sites',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> # Uncomment the next line to enable the admin:
> # 'django.contrib.admin',
> # Uncomment the next line to enable admin documentation:
> # 'django.contrib.admindocs',
> 'polls',
> )
>
> And here is my models.py:
>
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice = models.CharField(max_length=200)
> votes = models.IntergerField()
>

In python, indentation matters. Also, spelling matters just as much as
it does in other languages: IntergerField should be IntegerField. Try:

--8<---------------cut here---------------start------------->8---
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
--8<---------------cut here---------------end--------------->8---

Nick

Ian Foote

unread,
Dec 26, 2012, 2:47:56 PM12/26/12
to django...@googlegroups.com
Others have commented on your indentation. You also have a typo:

> votes = models.IntergerField()

should be:

votes = models.IntegerField()

Regards,
Ian

rktu...@gmail.com

unread,
Dec 26, 2012, 3:56:04 PM12/26/12
to django...@googlegroups.com
This is strange - the original code is indented correctly; however, the copy/paste shows incorrect indentation. I would have noticed something THAT obvious. The misspelling is legit, but what was wrong was that I had two files named"polls," which confused everything. 

Ramiro Morales

unread,
Dec 26, 2012, 5:16:30 PM12/26/12
to django...@googlegroups.com


On Dec 26, 2012 5:56 PM, <rktu...@gmail.com> wrote:
>
> This is strange - the original code is indented correctly; however, the copy/paste shows incorrect indentation.

This could happen if you mix spaces andás tabs. Read some introductory Python material to know more why this is a bad idea and a basic mistake.

Gerald Klein

unread,
Dec 26, 2012, 5:40:40 PM12/26/12
to django...@googlegroups.com
do you use vim? There is a nice function that can straighten this out for you. Also tabs va spaces can make a difference. Make sure a given block is either all space indented ot all tab indented. 

add to vimrc

set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<


then type 

:set list

this will show whitespace characters and highlight difference tabs/spaces to see them. 

--jerry

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--

Gerald Klein DBA

Cont...@geraldklein.com

www.geraldklein.com

geraldklein.wordpress.com

j...@zognet.com

708-599-0352


Arch Awesome, Ranger & Vim the coding triple threat.

Linux registered user #548580 


Reply all
Reply to author
Forward
0 new messages