Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Setting up the error handling templates


When Django encounters an error and needs to serve a 404 (Page Not Found) or 500 (Server Error) response, it looks for the files called 404.html and 500.html (respectively) in the root of your templates directory. If you have more than one directory in your TEMPLATE_DIRS setting, it will search each one in order until it finds the required file.

If it can't find the 404.html file, Django will serve a TemplateDoesNotExist error. If it can't find the 500.html file, you'll get the most generic-looking error page your web server provides.

Note

If you have debugging enabled in your settings.py file, Django will serve you a diagnostic error page and you won't see your 404.html or 500.html templates.

Creating the error templates

Let's add these error pages to our project. Create a new file called 404.html in the mycompany/templates directory and add these lines:

<html>
<head>
<title>Page Not Found</title>
</head>
<body>
&lt...