【问题标题】:500 error with Debug = False instead of 404500 错误与 Debug = False 而不是 404
【发布时间】:2015-05-10 17:39:58
【问题描述】:

在 Django 1.7 应用程序中:

# settings.py

DEBUG = False
ALLOWED_HOSTS = ['localhost', '127.0.0.1']

# urls.py
#.....
from myapp.views import handler404
handler404 = handler404

#myapp/views.py
def handler404(request):
  return render(request, '404.html')

但它仍然抛出 500 错误而不是 404。怎么会?有没有什么办法让它在页面真的找不到的时候生成404而不是500?

更新:

即使使用 Debug = True,它也会显示标准的 Django 404 页面。

【问题讨论】:

    标签: python django


    【解决方案1】:

    根据文档(docs.djangoproject.com/en/1.7/topics/http/views/)

    #from myapp.views import handler404
    handler404 = 'myapp.views.handler404'
    

    【讨论】:

    • 你想猜答案吗?
    • 您需要为您的答案提供更好的解释,他们为什么要尝试这个?
    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 2015-05-26
    • 2019-11-04
    • 2021-11-03
    • 2010-11-04
    • 2013-02-14
    • 2019-10-02
    • 2018-11-24
    相关资源
    最近更新 更多