Move Django settings inside try/except.

This is because the exception might not be raised until dir(settings) when
Django goes looking for DJANGO_SETTINGS_MODULE.