Fixed #8703 -- Allow deeply nested import paths for DJANGO_SETTINGS_MODULE when
running django-admin.py. Also adds a parameter to setup_environ() for others to use as well. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8768 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8f56d6d017
commit
79968f9867
|
@ -108,7 +108,7 @@ def get_commands():
|
|||
__import__(
|
||||
settings.SETTINGS_MODULE, {}, {},
|
||||
(settings.SETTINGS_MODULE.split(".")[-1],)
|
||||
)
|
||||
), settings.SETTINGS_MODULE
|
||||
)
|
||||
except (AttributeError, EnvironmentError, ImportError):
|
||||
project_directory = None
|
||||
|
@ -294,12 +294,15 @@ class ManagementUtility(object):
|
|||
else:
|
||||
self.fetch_command(subcommand).run_from_argv(self.argv)
|
||||
|
||||
def setup_environ(settings_mod):
|
||||
def setup_environ(settings_mod, original_settings_path=None):
|
||||
"""
|
||||
Configures the runtime environment. This can also be used by external
|
||||
scripts wanting to set up a similar environment to manage.py.
|
||||
Returns the project directory (assuming the passed settings module is
|
||||
directly in the project directory).
|
||||
|
||||
The "original_settings_path" parameter is optional, but recommended, since
|
||||
trying to work out the original path from the module can be problematic.
|
||||
"""
|
||||
# Add this project to sys.path so that it's importable in the conventional
|
||||
# way. For example, if this file (manage.py) lives in a directory
|
||||
|
@ -314,6 +317,9 @@ def setup_environ(settings_mod):
|
|||
sys.path.pop()
|
||||
|
||||
# Set DJANGO_SETTINGS_MODULE appropriately.
|
||||
if original_settings_path:
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
|
||||
else:
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
|
||||
return project_directory
|
||||
|
||||
|
|
Loading…
Reference in New Issue