ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

2,866 views
Skip to first unread message

ayayalar

unread,
Nov 10, 2008, 6:10:45 PM11/10/08
to Django users
Hello I am new to Django.

I am trying to exercise "templates" through the interactive shell,
however I end up getting this error. Can anyone help?

here is the exact steps I follow:

1) cd C:\Django\mysite

manage.py
settings.py
settings.pyc
urls.py
urls.pyc
views.py
views.pyc
__init__.py
__init__.pyc

2) set DJANGO_SETTINGS_MODULE=mysite.settings I've also tried set
DJANGO_SETTINGS_MODULE=settings.py

3) python


4) >>> from django.template import Template
>>> t = Template("My name is {{ name }}.")

5) ERROR: ImportError: Settings cannot be imported, because
environment variable DJANGO_SETTINGS_MODULE is undefined.

Karen Tracey

unread,
Nov 10, 2008, 9:29:21 PM11/10/08
to django...@googlegroups.com
On Mon, Nov 10, 2008 at 6:10 PM, ayayalar <ayay...@gmail.com> wrote:

Hello I am new to Django.

I am trying to exercise "templates" through the interactive shell,
however I end up getting this error. Can anyone help?

here is the exact steps I follow:

1) cd C:\Django\mysite

   manage.py
   settings.py
   settings.pyc
   urls.py
   urls.pyc
   views.py
   views.pyc
   __init__.py
   __init__.pyc

2) set DJANGO_SETTINGS_MODULE=mysite.settings I've also tried set
DJANGO_SETTINGS_MODULE=settings.py

Setting it to mysite.settings will work if c:\django is on your PYTHONPATH.

Setting it to settings.py won't work at all because of the .py.  Assuming you are running the python from c:\django\mysite, setting DJANGO_SETTINGS_MODULE to just 'settings' will work.  Or, use 'python manage.py shell', which assumes settings.py is in the current directory and sets the environment up for you.

Karen

ayayalar

unread,
Nov 10, 2008, 11:26:06 PM11/10/08
to Django users
Thank you for the reply Karen. your suggestion worked just fine.

On Nov 10, 9:29 pm, "Karen Tracey" <kmtra...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages