import os
import sys

sys.path.insert(0, os.path.dirname(__file__))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')

STARTUP_ERROR = None

try:
    from django.core.wsgi import get_wsgi_application
    _application = get_wsgi_application()
except Exception as e:
    import traceback
    STARTUP_ERROR = traceback.format_exc()
    
def application(environ, start_response):
    if STARTUP_ERROR:
        start_response('500 Internal Server Error', [('Content-Type', 'text/plain')])
        return [STARTUP_ERROR.encode('utf-8')]
    try:
        return _application(environ, start_response)
    except Exception as e:
        import traceback
        start_response('500 Internal Server Error', [('Content-Type', 'text/plain')])
        return [traceback.format_exc().encode('utf-8')]
