Ticket #9751: 9751-core_management_init-r10599.diff

File 9751-core_management_init-r10599.diff, 1.6 KB (added by gsong, 6 years ago)
  • django/core/management/__init__.py

     
    105105        # Find the project directory
    106106        try:
    107107            from django.conf import settings
    108             module = import_module(settings.SETTINGS_MODULE.split('.', 1)[0])
    109             project_directory = setup_environ(module,
    110                                                 settings.SETTINGS_MODULE)
    111         except (AttributeError, EnvironmentError, ImportError):
     108            module = sys.modules[settings.SETTINGS_MODULE]
     109            project_directory = setup_environ(module, settings.SETTINGS_MODULE)
     110        except (AttributeError, EnvironmentError, ImportError, KeyError):
    112111            project_directory = None
    113112
    114113        # Find and load the management module for each installed app.
     
    316315    # Add this project to sys.path so that it's importable in the conventional
    317316    # way. For example, if this file (manage.py) lives in a directory
    318317    # "myproject", this code would add "/path/to/myproject" to sys.path.
    319     project_directory, settings_filename = os.path.split(settings_mod.__file__)
     318    if '__init__.py' in settings_mod.__file__:
     319        p = os.path.dirname(settings_mod.__file__)
     320    else:
     321        p = settings_mod.__file__
     322    project_directory, settings_filename = os.path.split(p)
    320323    if project_directory == os.curdir or not project_directory:
    321324        project_directory = os.getcwd()
    322325    project_name = os.path.basename(project_directory)
Back to Top