#20050: Django models are not importable for utility scripts
-------------------------------+--------------------
Reporter: techtonik | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Other) | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------+--------------------
`application/models.py` often use `settings.py`, and because Django can
not import its own settings, an attempt to import models from ordinary
command line helper script fails.
My application layout:
{{{
+ codereview/
| + __init__.py
| + models.py
|
+ settings.py
+ data_schema.py
}}}
`data_schema.py`
{{{
from codereview import models
}}}
And the error:
{{{
...
File "codereview\models.py", line 676, in Account
default_context = db.IntegerProperty(default=settings.DEFAULT_CONTEXT,
File "...\django-1.4.5-py2.7.egg\django\utils\functional.py", line 184,
in inner
self._setup()
File "...\django-1.4.5-py2.7.egg\django\conf\__init__.py", line 40, 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.
}}}
I know about `os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'`
workaround. The questions are:
* Why users need to specify it every time explicitly?
* Why 'settings' is not the sane default?
* Why this error can not be shown only after Django actually fails to
find the settings?
--
Ticket URL: <https://code.djangoproject.com/ticket/20050>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.