views:

286

answers:

1

I wish to test my django project form IDLE shell in windows. I run following commands

from django.template import Template, Context
t = Template('test template')

but I get following error.

Traceback (most recent call last):


File "<pyshell#1>", line 1, in <module>
    t = Template('test template')
  File "C:\Program Files\Python26\lib\site-packages\django\template\__init__.py", line 164, in __init__
    if settings.TEMPLATE_DEBUG and origin is None:
  File "C:\Program Files\Python26\lib\site-packages\django\conf\__init__.py", line 28, in __getattr__
    self._import_settings()
  File "C:\Program Files\Python26\lib\site-packages\django\conf\__init__.py", line 59, in _import_settings
    self._target = Settings(settings_module)
  File "C:\Program Files\Python26\lib\site-packages\django\conf\__init__.py", line 94, in __init__
    raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'C:\Program Files\Python26\Lib\site-packages\django\conf' (Is it on sys.path? Does it have syntax errors?): Import by filename is not supported.

Can you help me out?

+2  A: 

Django needs to load several files like your settings.py. To help out with this task, Django comes bundled with its own shell (which can be IDLE). If you have IPython installed, Django will use it instead.

To get to the shell, use the manage.py file in your root directory:

python manage.py shell

If you still really want to use IDLE completely outside the scope of "./manage.py shell", look at the manage.py file to see how Django loads in all the required files.

As a bonus, look into django-command-extensions for shell_plus (it provides some nice additional features like loading all your models automatically).

John Paulett
Just to be clear, django doesn't really have 'it's own shell', it actually just uses your default python shell, but makes your project modules available to it before it starts.
TM
Thank you very much it solved... However I still wish to use it using IDLE...
Software Enthusiastic