(request, template_name='500.html', exception=None)
return HttpResponseServerError(t.render(
        context={
            'MEDIA_URL': settings.MEDIA_URL,
            'STATIC_URL': settings.STATIC_URL,
            'domain': domain,
            '500traceback': traceback_key,
            'sentry_event_id': last_event_id(),
        },
        request=request,
    ))
500 error handler.
500 error handler.
500 error handler .
def server_error(request, template_name='500.html', exception=None):
    """
    500 error handler.
    """
    urlname = resolve(request.path).url_name
    submission_urls = [
        'receiver_secure_post',
        'receiver_secure_post_with_app_id',
        'receiver_post_with_app_id'
    ]
    if urlname in submission_urls + ['app_aware_restore']:
        return HttpResponse(status=500)

    domain = get_domain_from_url(request.path) or ''

    # hat tip: http://www.arthurkoziel.com/2009/01/15/passing-mediaurl-djangos-500-error-view/
    t = loader.get_template(template_name)
    type, exc, tb = sys.exc_info()

    traceback_text = format_traceback_the_way_python_does(type, exc, tb)
    traceback_key = uuid.uuid4().hex
    cache.cache.set(traceback_key, traceback_text, 60*60)

    if settings.UNIT_TESTING:
        # Explicitly don't render the 500 page during unit tests to prevent
        # obfuscating errors in templatetags / context processor. More context here:
        # https://github.com/dimagi/commcare-hq/pull/25835#discussion_r343997006
        return HttpResponse(status=500)

    return HttpResponseServerError(t.render(
        context={
            'MEDIA_URL': settings.MEDIA_URL,
            'STATIC_URL': settings.STATIC_URL,
            'domain': domain,
            '500traceback': traceback_key,
            'sentry_event_id': last_event_id(),
        },
        request=request,
    ))
def server_error ( request , template_name = '500.html' , exception = None ) : urlname = resolve ( request . path ) . url_name submission_urls = [ 'receiver_secure_post' , 'receiver_secure_post_with_app_id' , 'receiver_post_with_app_id' ] if urlname in submission_urls + [ 'app_aware_restore' ] : return HttpResponse ( status = 500 ) domain = get_domain_from_url ( request . path ) or '' # hat tip: http://www.arthurkoziel.com/2009/01/15/passing-mediaurl-djangos-500-error-view/ t = loader . get_template ( template_name ) type , exc , tb = sys . exc_info ( ) traceback_text = format_traceback_the_way_python_does ( type , exc , tb ) traceback_key = uuid . uuid4 ( ) . hex cache . cache . set ( traceback_key , traceback_text , 60 * 60 ) if settings . UNIT_TESTING : # Explicitly don't render the 500 page during unit tests to prevent # obfuscating errors in templatetags / context processor. More context here: # https://github.com/dimagi/commcare-hq/pull/25835#discussion_r343997006 return HttpResponse ( status = 500 ) return HttpResponseServerError ( t . render ( context = { 'MEDIA_URL' : settings . MEDIA_URL , 'STATIC_URL' : settings . STATIC_URL , 'domain' : domain , '500traceback' : traceback_key , 'sentry_event_id' : last_event_id ( ) , } , request = request , ) )