views.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:django-project-template 作者: thorgate 项目源码 文件源码
def server_error(request, template_name='500.html'):
    if request.is_ajax() or request.META.get('HTTP_ACCEPT', 'text/plain') == 'application/json':
        return JsonResponse({
            'sentry': sentry_id_from_request(request),
            'error': {
                'title': _('Something went wrong'),
            }
        }, status=500)

    try:
        template = loader.get_template(template_name)
    except TemplateDoesNotExist:
        return HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html')

    message = _('Something went wrong on our side... \n Please hold on while we fix it.').replace('\n', '<br>')
    return HttpResponseServerError(template.render({
        'sentry': sentry_id_from_request(request),
        'error': {
            'title': _('Something went wrong'),
            'message': message,
            'sentry': _('Fault code: #'),
        }
    }))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号