http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/
On Apr 28, 5:10 pm, "Andrew D. Ball" <[EMAIL PROTECTED]> wrote: > Greetings. > > I'm working on a Django application and would like > to be able to write a stand-alone Python program > that calls my Django application directly. > > Accomplishing like seems to require me to import > the project settings file, which I've figured out > how to do. However, I'm still looking for how > to satisfy the rest of the requirements (which > are probably what 'python manage.py shell' > does for me...). > > I have the Python script in the application's > directory and am using some silly manipulation > of sys.path to import the module named 'settings' > in the previous directory (which is the Django > project directory). > > It looks like I need to set some environment > variables. Here's the error message I'm getting > when I try to import the application's models: > > [EMAIL PROTECTED]:$ python batch_process.py > Traceback (most recent call last): > File "batch_process.py", line 16, in ? > import models > File > "/home/nfs/aball/devel/power_reg/trunk/power_reg_2/pr2_core_services/models.py", > line 6, in ? > from django.db import models > File "/var/lib/python-support/python2.4/django/db/__init__.py", line 7, in ? > if not settings.DATABASE_ENGINE: > File "/var/lib/python-support/python2.4/django/conf/__init__.py", line 28, > in __getattr__ > self._import_settings() > File "/var/lib/python-support/python2.4/django/conf/__init__.py", line 53, > in _import_settings > raise EnvironmentError, "Environment variable %s is undefined." % > ENVIRONMENT_VARIABLE > EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined. > > Anybody know how to do this? > > Thanks for your help. > > Peace, > Andrew > ========================= > Andrew D. Ball <[EMAIL PROTECTED]> > software engineer > American Research Institute, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---