Ticket #5825: user_commands_path.patch

File user_commands_path.patch, 1.4 KB (added by andrew.mcmurry@…, 16 years ago)

Here is a very simple patch that will make sure that sys.path includes the project's containing directory while searching for the local app management modules.

  • django/core/management/__init__.py

     
    8787        except (AttributeError, EnvironmentError):
    8888            apps = []
    8989
     90        # Try to determine the project directory
     91        try:
     92            from django.conf import settings
     93            project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
     94        except (AttributeError, EnvironmentError, ImportError):
     95            project_directory = None
     96
     97        # Add the parent directory of the project directory to sys.path
     98        # so we can find the management modules.
     99        sys.path.append(os.path.join(project_directory, os.pardir))
     100
    90101        for app_name in apps:
    91102            try:
    92103                path = find_management_module(app_name)
     
    95106            except ImportError:
    96107                pass # No management module - ignore this app
    97108
    98         # Try to determine the project directory
    99         try:
    100             from django.conf import settings
    101             project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
    102         except (AttributeError, EnvironmentError, ImportError):
    103             project_directory = None
     109        sys.path.pop()
    104110
    105111        if project_directory:
    106112            # Remove the "startproject" command from self.commands, because
Back to Top