Fixed #20443 -- Import errors in settings cause confusing error messages

https://code.djangoproject.com/ticket/20443
Replacement for PR https://github.com/django/django/pull/1112.