#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

@@ -41,34 +41,1140 @@
 ys%0A%0A
-if __name__ == %22__main__%22:
+from django.core.management import CommandParser%0A%0A# It's nice if %22./manage.py test%22 works out-of-the-box, so work out if%0A# %22test%22 is the subcommand and the user hasn't specified a settings%0A# module with --settings.  If so, use the settings module for%0A# non-country-specific tests that we know has the right INSTALLED_APPS%0A# and tests are expected to pass with. This won't help confusion if%0A# someone uses %22django-admin.py test%22 instead, but it's some help...%0A# (Note that if someone's set the DJANGO_SETTINGS_MODULE environment%0A# variable, this default won't be used either.)%0A%0Atry:%0A    subcommand = sys.argv%5B1%5D%0Aexcept IndexError:%0A    subcommand = 'help'%0A%0Aparser = CommandParser(None)%0Aparser.add_argument('--settings')%0Atry:%0A    options, args = parser.parse_known_args(sys.argv%5B2:%5D)%0Aexcept:%0A    # Ignore any errors at this point; the arguments will be parsed%0A    # again shortly anyway.%0A    args = %5B%5D%0A%0Arun_default_tests = (subcommand == 'test' and not options.settings)%0A%0Aif __name__ == %22__main__%22:%0A%0A    if run_default_tests:%0A        settings_module = 'mysite.settings.tests'%0A    else:%0A        settings_module = 'mysite.settings.base'%0A
 %0A   
@@ -1226,24 +1226,16 @@
 E%22, 
-%22mysite.
 settings
 %22)%0A%0A
@@ -1230,17 +1230,23 @@
 settings
-%22
+_module
 )%0A%0A    f

Update manage.py for more flexible use of settings modules