python - 如何将 django 链接到我自己的 404 错误页面?

标签 python django django-templates

通常 django 在 url.py 文件中查找 url... 如果找到则加载相关 HTML 页面,如果没有找到则显示: 找不到页面 (404) 消息:

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

我想更改 django 显示的标准 404 页面。我有一个我创建的 HTML 页面 PageNotFound.html 我希望 django 在每次 DEBUG = False 出现 Page not find (404) 时显示>。我该怎么做?

最佳答案

In order to show customized HTML when Django returns a 404, you can create an HTML template named 404.html and place it in the top level of your template tree. This template will then be served when DEBUG is set to False.

https://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view

此外,还有一个有用的部分“自定义错误 View ”。

如果您想在设置 DEBUG=False 的情况下测试模板,您可以运行 manage.py runserver --insecure。 即使 DEBUG 设置为 False,它也会强制 Django 使用 staticfiles 应用程序提供静态文件。但请注意,它仅用于本地开发并且可能不安全。您可以阅读有关此选项的更多信息 here .

关于python - 如何将 django 链接到我自己的 404 错误页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32497589/

相关文章:

django - 如何将单个参数的多个值传递到 Django Rest Framework 中的 API url?

python - Django 创建新项目 - 访问被拒绝

Python 3.7,MySql-Python 的构建轮失败

django - "render"这个词在django中是什么意思?

javascript - 将所有 Javascript 移动到 Django 中的单独文件

python - 在 pyqt 中应用样式表

python - 是列表[i :j] guaranteed to be an empty list if list[j] precedes list[i]?

python - 模板参数是否可以等于另一个元素的值?

python - Anaconda: cannot import cv2 even though opencv is installed (how to install opencv3 for python3)

python - 来自 SQL Server 的 "Invalid precision or scale value"错误,使用 pypyodbc for Decimal( '0.00' )、Decimal( '0.12' )