【问题标题】:Django custom 404 page not recognizedDjango 自定义 404 页面无法识别
【发布时间】:2020-05-30 15:58:51
【问题描述】:

我已在我的根模板目录中放置了一个自定义 404.html 页面,但每当请求无效 URL 时,都会给出默认错误页面。奇怪的是,在生产中,显示“内部服务器错误”,而“未找到。 在此服务器上未找到请求的资源。”显示在 localhost 上。

Debug 在这两种情况下都设置为 false。

app/templates/app/404.html:

{% extends "app/base.html" %}

{% block page_header %}
    <h1>404</h1>
    <h2>The page you requested is not available.</h2>
    <i class="far fa-meh"></i>
{% endblock page_header %}

【问题讨论】:

    标签: django django-templates


    【解决方案1】:

    我必须在根目录(而不是应用程序文件夹)中创建一个没有任何子文件夹的新模板文件夹。该文件现在位于root/templates/404.html

    【讨论】:

      猜你喜欢
      • 2011-11-21
      • 2013-12-27
      • 2017-10-18
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 2014-01-02
      • 2018-11-16
      相关资源
      最近更新 更多