try:
# тут весь скрипт как есть
except:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
file("/tmp/log", "a").write( "Exception %s at %s:%s"%(exc_type, fname, exc_tb.tb_lineno))
import os, sys
sys.path.append('c:\path\to\project')
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
from my_app.models import blablabla