Domanda

Maybe it's because I am more comfortable with python over the shell, but I chose to add to my sys.path list in /usr/lib/python[x.x]/sitecustomize.py in this manner:

base = '/home/droogans/py/'

locs = ['foo','django']

for loc in locs:
    sys.path.insert(0, base + loc)

And now I've added a try:except block below it, in case I want to test out a template without using the python manage.py shell approach.

try:
    from django.core.management import setup_environ
    from website_foobar import settings
    setup_environ(settings)
except ImportError:
    pass

The DjangoBook has a section, "A special python prompt", that recommends you do this, but suggests using your .bash_profile shell script for the task. Is there a measurable benefit to utilizing that instead of a sitecustomize.py script? Obviously, I'm already done, so there'll have to be some kind of compelling evidence for me to google an article on writing shell code.

È stato utile?

Soluzione

Sometimes you are not going to have superuser status on the machine you are using. In such cases you won't be able to modify /usr, so it would be necessary then to know how to set environment variables in your personal ~/.bashrc or ~/.profile or ~/.bash_profile. (The particular file to use depends on your system).

It's not hard to do. All you'd need to add (I think!) is something like

PYTHONPATH=$HOME/py/foo:$HOME/py/django
DJANGO_SETTINGS_MODULE=website_foobar.settings

export PYTHONPATH DJANGO_SETTINGS_MODULE
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top