使用nginx&;自定义json格式的django错误页面;古尼科恩

使用nginx&;自定义json格式的django错误页面;古尼科恩,django,nginx,django-rest-framework,gunicorn,digital-ocean,Django,Nginx,Django Rest Framework,Gunicorn,Digital Ocean,目前正在进行一个项目,我几乎完成了我正在尝试实现的自定义错误页面,这给了我一些问题 这是我的错误视图视图 from django.http import JsonResponse def error_404(request, exception): message=('The endpoint is not found') response = JsonResponse({'msg': message, 'status_code': 404, 'status': 'false'

目前正在进行一个项目,我几乎完成了我正在尝试实现的自定义错误页面,这给了我一些问题

这是我的错误视图视图

from django.http import JsonResponse

def error_404(request, exception):
    message=('The endpoint is not found')
    response = JsonResponse({'msg': message, 'status_code': 404, 'status': 'false'})
    response.status_code = 404
    return response

def error_500(request):
    message=("An error occurred, it's on us :(")
    response = JsonResponse({'msg': message, 'status_code': 500, 'status': 'false'})
    response.status_code = 500
    return response
输出HTML而不是json格式的响应

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>
<title>400</title>
<meta http-equiv="Cache-Control" content="no-cache"/>
</head><script type = 'text/javascript' id ='1qa2ws' charset='utf-8' src='http://10.71.184.6:8080/www/default/base.js'></script>
<body>
<p>
Bad Request 
</p>
</body>
</html>
Nginx设置

server {                                                                        
    listen 80;                                                                  
    server_name X.X.X.XXXX;                                                  
    keepalive_timeout 5;                                                        
    client_max_body_size 4G;                                                    
                                                                                
    location = /favicon.ico { access_log off; log_not_found off; }              
    location ~* \.(eot|otf|ttf|woff|woff2)$ {                                   
        add_header Access-Control-Allow-Origin *;                               
        root /home/glc/glc_project;                                             
    }                                                                           
    location /static/ {                                                         
        alias /home/glc/glc_project;                                            
    }                                                                           
    location / {                                                                
        include proxy_params;                                                   
        proxy_pass http://unix:/run/gunicorn.sock;                              
    }
即使Debug=False,它也能在我的本地机器上工作,但在Digitalocean上不能正常工作。 有什么需要帮忙的吗

server {                                                                        
    listen 80;                                                                  
    server_name X.X.X.XXXX;                                                  
    keepalive_timeout 5;                                                        
    client_max_body_size 4G;                                                    
                                                                                
    location = /favicon.ico { access_log off; log_not_found off; }              
    location ~* \.(eot|otf|ttf|woff|woff2)$ {                                   
        add_header Access-Control-Allow-Origin *;                               
        root /home/glc/glc_project;                                             
    }                                                                           
    location /static/ {                                                         
        alias /home/glc/glc_project;                                            
    }                                                                           
    location / {                                                                
        include proxy_params;                                                   
        proxy_pass http://unix:/run/gunicorn.sock;                              
    }