Opened 15 years ago
Closed 14 years ago
#14720 closed Cleanup/optimization (fixed)
Settings imported twice as separate modules when manage.py is used
| Reported by: | Piotr Czachur | Owned by: | Brett Haydon |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Someday/Maybe | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Some people may be surprised that settings are loaded twice under different names in sys.modules:
- import 1) as 'settings' (manage.py, imported in same-dir fashion)
- import 2) as "projectname.settings" (import_module() triggered when LazySettings is accessed first time; projectname/__init__.py is loaded)
Simple solution is to replace
import settings # Assumed to be in the same directory.
with
# Project module is known during manage.py creation, because it's django-admin startproject parameter.
from project_module import settings
This change affects package/module loading order:
projecname/__init__.py will be executed during importing of settings inside manage.py.
Change History (5)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Someday/Maybe |
| Version: | 1.2 → SVN |
Note: you cannot use 'from project_module import settings' unless you have explicitly added project_module to your PYTHONPATH
Graham Dumpleton has a good post on this:
http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
comment:3 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Cleanup/optimization |
comment:4 by , 14 years ago
| Easy pickings: | unset |
|---|---|
| UI/UX: | unset |
I suspect that this might be resolved now after changeset:16964. Just need someone confirmation to close the ticket.
comment:5 by , 14 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
This was indeed fixed by r16964 - didn't realize there was a ticket open for it.
I was bitten by the current behavior as well, I agree that it is quite annoying.