diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index a49ffdd3b8d..7b667e7c8f0 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -306,19 +306,10 @@ class ManagementUtility(object): except CommandError: pass # Ignore any option errors at this point. - no_settings_commands = [ - 'help', 'version', '--help', '--version', '-h', - 'startapp', 'startproject', 'compilemessages', - ] - try: settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc - # A handful of built-in management commands work without settings. - # Load the default settings -- where INSTALLED_APPS is empty. - if subcommand in no_settings_commands: - settings.configure() if settings.configured: # Start the auto-reloading dev server even if the code is broken. diff --git a/django/core/management/base.py b/django/core/management/base.py index 3726d421506..6aaf2fc4bb9 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -303,7 +303,12 @@ class BaseCommand(object): self.stderr.write('%s: %s' % (e.__class__.__name__, e)) sys.exit(1) finally: - connections.close_all() + try: + connections.close_all() + except ImproperlyConfigured: + # Ignore if connections aren't setup at this point (e.g. no + # configured settings). + pass def execute(self, *args, **options): """ diff --git a/django/core/management/templates.py b/django/core/management/templates.py index fd957fbabf9..466ea935d8d 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -11,6 +11,7 @@ import tempfile from os import path import django +from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.core.management.utils import handle_extensions from django.template import Context, Engine @@ -119,9 +120,9 @@ class TemplateCommand(BaseCommand): }), autoescape=False) # Setup a stub settings environment for template rendering - from django.conf import settings if not settings.configured: settings.configure() + django.setup() template_dir = self.handle_template(options['template'], base_subdir)