diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 74e2b9d211..6f883ee7bb 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -104,7 +104,12 @@ def get_commands(): # Find the project directory try: from django.conf import settings - project_directory = setup_environ(__import__(settings.SETTINGS_MODULE)) + project_directory = setup_environ( + __import__( + settings.SETTINGS_MODULE, {}, {}, + (settings.SETTINGS_MODULE.split(".")[-1],) + ) + ) except (AttributeError, EnvironmentError, ImportError): project_directory = None @@ -310,6 +315,7 @@ def setup_environ(settings_mod): # Set DJANGO_SETTINGS_MODULE appropriately. os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) + return project_directory def execute_from_command_line(argv=None): """