Opened 16 years ago
Closed 15 years ago
#11633 closed (worksforme)
Stop requiring DJANGO_SETTINGS_MODULE when using settings.configure
| Reported by: | Masklinn | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Keywords: | settings | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Currently, django requires both that there is a DJANGO_SETTINGS_MODULE environment variable and that it points to an actual module, even though it's not necessary when calling django.config.settings.configure.
Therefore to use Django modules in standalone system (or when testing an application on its own without a project, as in #11593) one has to either create an empty settings file (which kind-of defeats the point of using settings.configure in the first place) or programmatically create a DJANGO_SETTINGS_MODULE environ set to a dummy module name and generate the corresponding dummy module in settings.modules e.g.
os.environ['DJANGO_SETTINGS_MODULE'] = "durrrrr"
sys.modules['durrrrr'] = type('IMA_MODULE', (), {})()
from django.conf import settings
# call settings.configure() here
Now while this isn't exactly hard to do (if you understand how module imports work & everything), it's annoying to have to do it and it can conflict with other modules if the dummy name isn't correctly chosen. It's also a waste of time on the user's side.
Change History (4)
comment:1 by , 16 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 15 years ago
comment:3 by , 15 years ago
This doesn't appear to be the case anymore:
>>> import os
>>> from django.conf import settings
>>> print os.environ.get("DJANGO_SETTINGS_MODULE", None)
None
>>> settings.configure(**{"foo": "bar"})
>>> settings.foo
'bar'
Sorry for the double post, formatting was messed up the first time.
comment:4 by , 15 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
This doesn't appear to be the case anymore:
None
'bar'