Hi all,
I'm trying to figure out correct overall and settings path usage
strategy for my Django applications.
What I am experiencing now is that settings.py is imported 4 times on
"python manage.py runserver" command,
twice as "settings", and twice as "myapp.settings", given that my
project is named "myapp".
It also doesn't care if I set DJANGO_SETTINGS_MODULE env option and
PYTHONPATH env option.
My desire is to make it use "settings", and don't ever use project
prefix "myapp."
Because this will cause much greater app reusability in different
projects, because of "blog" project and "blog" application possible
import clashes (and weird errors from urlconf loader), because I want
to be able to rename project at any moment, because i want "111" or
"project-v1.1" to be also correct project folders. This is my general
rule: my apps shouldn't start with project prefix.
So I was struck when I've found the following lines in setup_environ:
if original_settings_path:
os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
else:
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' %
(project_name, settings_name)
Why it does so?
Next, I found why setup_environ is called 4 times: twice with
original_settings_path = None, twice with original_settings_path =
'myapp.settings' (and giving the following entry in sys.modules:
<module 'myapp.settings' from
'/Projects/django/myapp/../myapp/settings.pyc'>).
Twice is because of autoreloader, which spawns new process.
So, to summarize:
settings is loading 4 times because it's loading twice as "settings"
from manage.py module, and twice as "work.settings" from
django.core.management.get_commands, see a piece of code below:
# Find the project directory
try:
from django.conf import settings
module = import_module(settings.SETTINGS_MODULE)
project_directory = setup_environ(module, settings.SETTINGS_MODULE)
except (AttributeError, EnvironmentError, ImportError, KeyError):
project_directory = None
Ok, runserver process spawning is an exception to other commands, so I
now want to remove only "work.settings" imports. What should I do? Is
there something we should improve? Is there something we should
document?
I'll be happy to make any required patches or writings.
Currently my fix is to patch setup_environ:
os.environ['DJANGO_SETTINGS_MODULE'] = '%s' % settings_name
And I commented these lines, I don't understand why they are needed at
all with my setup, they won't make project directory work without
__init__.py (and in other cases it can't be imported):
# Import the project module. We add the parent directory to PYTHONPATH to
# avoid some of the path errors new users can have.
#sys.path.append(os.path.join(project_directory, os.pardir))
#project_module = import_module(project_name)
#sys.path.pop()
--
Best regards, Yuri V. Baburov, ICQ# 99934676, Skype: yuri.baburov,
MSN: [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---