Avoided catching ImproperlyConfigured on django.setup().

Fixed #21737. Thanks Florian for the report.

Also removed redundant imports in that file.