[Answer]-Django Tutorial 1: cannot fix error "File "<console>", line 1, in <module>ImportError: cannot import name Choice"

1๐Ÿ‘

I believe that your file structure is wrong. It should be:

--mysite
 |--manage.py
 |--polls
   |--models.py
 |--mysite
   |--settings.py
   |--urls.py

Instead do you have this?

--mysite
 |--manage.py
 |--mysite
   |--polls
     |--models.py
   |--settings.py
   |--urls.py

If the file structure was correct, and there was something else wrong, then the error code would be something like this

>>> from polls.models import Poll, Choice
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "polls/models.py", line 1, in <module>
    from django.db import models
  File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/usr/lib/python2.6/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
๐Ÿ‘คDan Mantyla

Leave a comment