On Fri, May 23, 2008 at 4:08 PM, David Robinson <[EMAIL PROTECTED]> wrote:

>
> Karen Tracey wrote:
> > manage.py doesn't set the environment variable, it just imports settings
> > assuming it is in the current directory.  Since you don't get an error
> > message that that failed, presumably it worked so the question is why is
> > some subsequent code trying to use the environment variable even though
> > settings has already been loaded.  To help answer that question, the full
> > traceback from the error case would be helpful.
>
> Karen,
>
> Here is the traceback. What you said did help me make a little more
> sense out of what's going on - Django is clearly getting to the settings
> file. But, then I get lost.
>
> Dave
>
>
> /usr/web/myproject/> python manage.py shell
> Traceback (most recent call last):
>   File "manage.py", line 14, in <module>
>     execute_manager(settings)
>   File
>
> "/usr/local/lib/python2.5/site-packages/django/core/management/__init__.py",
> line 270, in execute_manager
>     project_directory = setup_environ(settings_mod)
>   File
>
> "/usr/local/lib/python2.5/site-packages/django/core/management/__init__.py",
> line 251, in setup_environ
>     project_module = __import__(project_name, {}, {}, [''])
>   File "/usr/web/myproject/../myproject/__init__.py", line 1, in <module>
>     from apps import admin
>   File "/usr/web/myproject/../myproject/apps/admin.py", line 1, in <module>
>     from django.contrib import admin


Here's where things start going south.  As part of trying to set up the
environment, Django tries to import your project.  But your project's
__init__.py file then goes and tries to import some stuff
(django.contrib.admin) that relies on the environment already being set up.
But the setup_environ function hasn't yet reached the point where it sets
the DJANGO_SETTINGS_MODULE environment variable, so unless you've already
set it yourself, you get the error.

So what's changed, I'm guessing, to introduce this problem is you added this
import to to your project's __init__.py file.  Now, it looks like the
setup_environ function could actually do the environment variable setting a
bit earlier (see
http://code.djangoproject.com/browser/django/trunk/django/core/management/__init__.py#L235--
it seems lines 255-256 could be moved to just below line 249, before
the
__import__, and then I think you wouldn't see this problem), but it'd
probably be easier to find another way to solve in your own code whatever
problem that added import was trying trying to fix.

Karen


>   File
> "/usr/local/lib/python2.5/site-packages/django/contrib/admin/__init__.py",
> line 1, in <module>
>     from django.contrib.admin.options import ModelAdmin
>   File
> "/usr/local/lib/python2.5/site-packages/django/contrib/admin/options.py",
> line 5, in <module>
>     from django.contrib.contenttypes.models import ContentType
>   File
>
> "/usr/local/lib/python2.5/site-packages/django/contrib/contenttypes/models.py",
> line 1, in <module>
>     from django.db import models
>   File "/usr/local/lib/python2.5/site-packages/django/db/__init__.py",
> line 10, in <module>
>     if not settings.DATABASE_ENGINE:
>   File
> "/usr/local/lib/python2.5/site-packages/django/conf/__init__.py", line
> 28, in __getattr__
>     self._import_settings()
>   File
> "/usr/local/lib/python2.5/site-packages/django/conf/__init__.py", line
> 57, in _import_settings
>     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.
>
>
> >
>

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

Reply via email to