1

如何处理我想为那些创建404, 403, 500 error的.django?customized pageerrors

4

1 回答 1

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')
于 2013-01-27T15:13:22.147 回答