【问题标题】:Django custom 405 template not being loaded未加载 Django 自定义 405 模板
【发布时间】:2020-10-02 19:15:46
【问题描述】:

我正在使用视图装饰器@require_http_methods(["POST"])。如果发送了除了 post 请求之外的任何内容,它应该将用户重定向到自定义 405 错误页面。

405.html 模板位于文件夹root/templates/405.html 内。 Django 的默认 405 页面会显示(纯 html 错误页面),但是,当发生错误时。此模板文件夹中的所有其他错误模板(404.html、500.html)都可以正常工作。这是为什么呢?

【问题讨论】:

标签: django


【解决方案1】:

请参考这个问题:

How to display a custom error page for HTTP status 405 (method not allowed) in Django when using @require_POST

没有针对 405 错误的默认处理程序。您需要实现自定义中间件来捕获 405 错误并重定向到自定义模板视图。

【讨论】:

    猜你喜欢
    • 2016-02-25
    • 2017-07-29
    • 2019-06-06
    • 2012-11-15
    • 2010-11-15
    • 2011-07-10
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    相关资源
    最近更新 更多