On 9/28/07, Jason Witherspoon <[EMAIL PROTECTED]> wrote:
....
> Okay, I'm guessing a Python reload would indeed help, as I've managed to get
> the Python debugger to find mysite.drpack.views by forcing the paths into
> sys.path:
>
> >>> sys.path.append('/my/new/path')
>
> ...rather than via the symlink method.

That doesn't really make sense.   With the symlink method, can you
import mysite?  Can you print sys.path with the symlink approach, then
try to import, then show the path you were trying to import.

Not to be rude, but is it named "mysite" or is it named "site"?
That's a common mistake.  Django has a built-in site module which is
responsible for setting up the python path, including site-packages.
It sounds like this is what you're running into.

To see what's going on here, try this
>>> import sys
>>> print sys.modules['site']

Please report the results.

>...Seems like this doesn't alter the
> sys.path permanently, though, as the paths I append evaporate a bit later
> when I leave IDLE & re-check sys.path....?

That's certainly true.  Python has some paths that it has on the path
by default, plus those specified in the PYTHONPATH environment
variable, plus any paths specified in .pth files, assuming the
standard python site module is doing its job.  Any changes you make to
sys.path affect only the process (and forked children, I guess) in
which you make the change.  It is, after all, just a python list.

> NOW, the problem is I'm getting:
>
> EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined
> (more fully:
>
OK, this is another common mistake.  I'm guessing development, you use
./manage.py runserver with the default settings.py file.

manage.py just assumes your settings file is somewhere on the python
path (e.g. in the current directory, which is generally in the
standard python path) and calls "import settings".

If you want to tell django where to load your settings file, and
you're not using manage.py, you need to set the DJANGO_SETTINGS_MODULE
environment variable.
http://www.djangoproject.com/documentation/settings/#using-settings-without-setting-django-settings-module


> After doing some research, it seems that manually configuring settings at
> runtime might help:
>
> http://www.djangoproject.com/documentation/settings/#using-settings-without-setting-django-settings-module
>

That's a fairly unusual approach, which exists for people that are
using only a small part of Django and who don't want to mess with
configuration much outside their one-off script.

Assuming your python path is set up correctly, you should be able to
do something like this:

DJANGO_SETTINGS_MODULE=mysite.settings python -m pdb ../path/to/mysite/views.py

Or, to test your path stuff, you should be able to fiddle with
PYTHONPATH on the commandline, like so:

PYTHONPATH=/some/path:/another/path/
DJANGO_SETTINGS_MODULE=mysite.settings python -m pdb
../path/to/mysite/views.py

Backing up a bit, go to the directory with views.py, and at a standard
django prompt, try to import:
from mysite.drpack.models import PubMedSummary

If not, make sure that drpack has an __init__.py file (which enables
drpack to behave as a package, a container for other modules.)

You might also show your whole stack trace; it's possible you have a
circular import such that drpark.models can't be properly initialized
before running into an exception.

To understand import better, this might help:
http://effbot.org/zone/import-confusion.htm

(I disagree with the general advice to always use import rather than
from ... import, but his is probably the better opinion.)

Cheers,
  Jeremy

--~--~---------~--~----~------------~-------~--~----~
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