Moved django settings import inside try-except block
Updated exec