如果我使用get_object_or_404()
,Django会显示正确的错误页面,但NGINX仍会返回:
HTTP/1.1 200 OK
Server: nginx
tl; tr
每页返回200或(如果500)超时。这有什么不对吗?
NGINX conf:
location / {
proxy_pass http://unix:/opt/repo/page.sock;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
}
urls.py
from django.conf import settings
handler404 = 'my_app.views.page_not_found'
答案 0 :(得分:1)
你应该设置处理程序,这可以这样做:
from django.utils.functional import curry
handler404 = curry(page_not_found, template_name='404.html')
handler500 = curry(page_not_found, template_name='500.html')
handler403 = curry(page_not_found, template_name='403.html')
我在urls.py中做过这个,但也可以在s
中完成