• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Django/python help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Stratus_ss

Overclockix Snake Charming Senior, Alt OS Content
Joined
Jan 24, 2006
Location
South Dakota
So I have a question for you fine folks.

If I run
Code:
/usr/lib/python2.6/site-packages/django/conf/project_template/manage.py shell

And run my code interactively, it works fine.

If I run just plain python shell and run the following I get errors:

Code:
>>> import django
>>> from django_akamai import purge
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/django_akamai-0.0.1-py2.6.egg/django_akamai/purge.py", line 48, in <module>
    from django.db.models.query import QuerySet
  File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 14, in <module>
    if not settings.DATABASES:
  File "/usr/lib/python2.6/site-packages/django/utils/functional.py", line 276, in __getattr__
    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.

I have tried googling for this error, but since I did not write the module, I do not see/cannot locate any .settings file for the module

Anyone have something to nudge me in the correct direction?

EDIT: here are the modules listed in regular python interactive mode (I have trimmed most of them for brevitiy)

Code:
_codecs_tw          distutils           opcode              sys
_collections        django              operator            syslog
_crypt              django_akamai       optparse            tabnanny
_csv                dl                  os                  tarfile
 
Last edited:
I have found my own workaround but I would still like to know a bit of what is going on here if possible


From Stack Overflow:

Code:
# set up the environment using the settings module
from django.core.management import setup_environ
from myapp import settings
setup_environ(settings)
 
If you're manually running the django shell a couple of times, you can set the DJANGO_SETTINGS_MODULE environment variable on the shell before running manage.py. If I'm just quickly checking something I'll do this:
Code:
DJANGO_SETTINGS_MODULE=myproject.settings
on the shell before running manage.py.

The easiest thing to do, if you're working long-term or switching between multiple projects, is to use a separate virtualenv for each project, and add that line to the activate script for your virtualenv.

/EDIT: I realize that I may have misinterpreted your question somewhat. Every Django project should have its own settings.py file/module with specifies things like database connections and other config options. If you're trying to run somebody's Django app (by app I mean self-contained module, not a whole Django project) outside the context of a Django project then you'll have this kind of problem.
 
Last edited:
Back