如何处理404, 403, 500 error
中的django?
我想为那些customized page
创建errors
。
答案 0 :(得分:2)
首先,创建404.html,403.html和500.html。
例如403.html
{% extends "base.html" %}
{% block title %}{{block.super}}Forbidden{% endblock %}
{% block content %}
<div id="container">
<h1>403</h1>
<h2>Forbidden</h2>
</div>
{% endblock %}
在您的base.html中:
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{{STATIC_URL}}css/style.css?v=1">
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
将它放在你的url.py
中#handle the errors
from django.utils.functional import curry
from django.views.defaults import *
handler500 = curry(server_error, template_name='500.html')
handler404 = curry(page_not_found, template_name='404.html')
handler403 = curry(permission_denied, template_name='403.html')