自定义路径中的Django错误模板

2024-04-19 03:12:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有dir模板和所有模板,我有dir错误,所有模板有错误404.html。 我找到了以下老办法:

在网址.py我写的应用程序

from django.conf.urls import (handler400, handler403, handler404, handler500)
handler404 = 'my_app.views.page_not_found'

查看我的应用程序

^{pr2}$

但我使用django1.11,这不起作用。在


Tags: djangofrompyimport模板应用程序confhtml
1条回答
网友
1楼 · 发布于 2024-04-19 03:12:52

如果你遵循docs

您应该返回HttpResponseNotFound,它与HttpResonse相同,只是状态代码不同。它对我有用。在

def bad_request(request):
    response = render_to_response(
        'errors/404.html'
    )

    return HttpResponseNotFound(response.content)

相关问题 更多 >