【问题标题】:How to add custom page for 403 error django如何为 403 错误 django 添加自定义页面
【发布时间】:2021-12-09 14:07:33
【问题描述】:

问题如标题。如何为 django 中的错误设置自定义页面。我尝试在模板中使用 '403.html' 这样的新文件,但它不起作用。 我也试过这个:

def handler404(request, exception, template_name="404.html"):
    response = render_to_response(template_name)
    response.status_code = 404
    return response

但我无法导入 render_to_response

【问题讨论】:

    标签: python django


    【解决方案1】:

    403 错误有两种不同的版本,一种专门针对 CSRF 问题。

    除了403.html之外,您可能还需要使用名为403_csrf.html的模板

    更多信息可以在以下链接中找到:

    【讨论】:

      猜你喜欢
      • 2012-01-31
      • 2017-06-11
      • 2019-11-28
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 2020-01-21
      • 1970-01-01
      相关资源
      最近更新 更多