通常 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/