Moved django settings import inside try-except block