首页 > 解决方案 > Errno 5 request.GET 输入/输出错误

问题描述

一旦我的 Django 站点被部署到“生产”并使用 Gunicorn 和 nginx 设置为实时,一些之前确实有效的 URL 现在会导致 [Errno 5] 输入/输出错误。我已经通过设置 DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False' 在 settings.py 中禁用了 DEBUG flat

解决此问题的最佳方法是什么?我忽略了部署的任何明显部分吗?

我的 nginx conf.d 文件如下所示:

server {
listen 80 default_server;
server_name rafalkukawski.tech; 
root /var/www/;

location / { 
    proxy_pass http://localhost:8000;
}   
location /img/ {
}   
location /static/ {
    autoindex on; 
}   

}

受此影响的观点有:

# called like: http://rafalkukawski.tech/todo/new?todo_name=new&due_date=2021-03-25&importance=0&required_time=1
def new_item(request):
    todo_name = request.GET.get('todo_name', '') 
    #todo_auth = request.GET.get('todo_auth', '')
    due_date = request.GET.get('due_date', '') 
    importance = request.GET.get('importance', '0')
    required_time = request.GET.get('required_time', '1') #this in particular is highlightet as the faulty line of code 
    item =  todo_item(todo_name = todo_name, todo_auth = request.user.username, due_date = due_date, importance = importance, required_time = required_time) 
    item.save()
    
    return HttpResponse(item.due_date)

或者

#called like: http://rafalkukawski.tech/ap/painting/1

#not sure what line exactly is causing this since the error only displays "<source code not available>" 

def template_painting(request, painting_id): 
    painting = Painting.objects.get(pk=painting_id)
    images = Imgs.objects.filter(painting=painting_id)
    lang_code = request.LANGUAGE_CODE
    
    template =loader.select_template(['ap/'+lang_code+'/painting.html','ap/en/painting.html'])
    #template = loader.get_template('ap/'+lang_code+'/painting.html')
    context = {"painting":painting, "images":images}
    return HttpResponse(template.render(context, request))

标签: pythonpython-3.xdjangonginxgunicorn

解决方案


推荐阅读