def execute_from_command_line(): from django.core.management import setup_environ sys.path.append(projectpath)
try: import settings except ImportError: print "You don't appear to have a settings file in this directory!" print "Please run this from inside a project directory" sys.exit() setup_environ(settings) 2009/7/2 Harsha Reddy <nhar...@gmail.com>: > > after setting the var: > export DJANGO_SETTINGS_MODULE=pyMyApp.settings > > it works!! > > Thanks a lot! > > On Jul 2, 1:25 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: >> On Jul 2, 8:25 am, Harsha Reddy <nhar...@gmail.com> wrote: >> >> >> >> > I using Django from past one week. >> >> > On the Django web site, I read that it is a high-level python web >> > framework. Inspite of knowing this I am trying to use a Django >> > application both as a web application as well as a CLI client. >> >> > To know if this works out, I created a Django project named "pyMyApp" >> > and added an application into it. >> > I updated the: >> >> > settings.py to detect my application, >> > also models.py to create two tables. >> >> > I have an other python file in the application which parses XML. This >> > python file makes use of objects defined in the models.py to store the >> > parsed values in those 2 tables. >> >> > In the directory "../" where my "pyMyApp" resides, I created a file >> > index.py added the code to test the parser code. Runnning this file >> > yeilds: >> >> > python index.py >> > Traceback (most recent call last): >> > File "index.py", line 3, in ? >> > from pyAPP.translator.translate import * >> > File "/usr/src/pySCAF/translator/translate.py", line 3, in ? >> > from pySCAF.translator.models import duo, scenario >> > File "/usr/src/pySCAF/../pySCAF/translator/models.py", line 1, in ? >> > from django.db import models >> > File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line >> > 10, in ? >> > if not settings.DATABASE_ENGINE: >> > File "/usr/lib/python2.4/site-packages/django/utils/functional.py", >> > line 269, in __getattr__ >> > self._setup() >> > File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", >> > line 38, 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. >> >> > By looking at the trace, I got a thought that "Django is designed to >> > be used as web framework" >> > if at all I want to use it both as cli and web apps, how to achieve >> > this in the case above? >> >> Did you try doing what the error says - setting the >> DJANGO_SETTINGS_MODULE environment variable? >> >> The error has nothing to do with whether you are running as a web app >> or not. >> -- >> DR. > > > > --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---