I have a problem with Django settings. My app runs with app-engine-patch. I added a script that runs without django, and is reached directly via the app.yaml handlers. I then get this error:
File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/__init__.py", line 53, in _import_settings
raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
<type 'exceptions.EnvironmentError'>: Environment variable DJANGO_SETTINGS_MODULE is undefined.
I found this tip in google:
# Force Django to reload its settings.
from django.conf import settings
settings._target = None
# Must set this env var before importing any part of Django
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
But then I got this error:
raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
<type 'exceptions.EnvironmentError'>: Could not import settings 'settings.py' (Is it on sys.path? Does it have syntax errors?): No module named ragendja.settings_pre
I think it is a problem with app-engine-patch paths modification, how can I import settings_pre correctly?
Thanks!
Thanks to another question, I replaced the beinning with:
from common.appenginepatch.aecmd import setup_env
setup_env(manage_py_env=True)
This imports all the settings and my task can run without reference to Django