Django Flatpages with Debug Set to False

After deploying a site I am working on to a preview server running apache/mod_python, it was the first time serving up the site in something other than python runserver.

I worked through a number of issues that I found quick answers for on the FAQ site for django, but one in particular I couldn't figure out, but eventually got pointed to the obvious in the irc channel for django.

The site has a number of flatpages, which I have come to learn is a middleware trick where when a url doesn't match anything and right before a 404 normally would be thrown giving the Page Not Found error, it checks against any flatpage "urls" you have registered the database with static content. If it finds something it will return that content, if not the 404 bubbles back out of the middleware and goes to the user.

Everything worked fine with DEBUG=True in my file. However, when I changed it to DEBUG=False, I got a 500 Internal Server Error but then when I looked at my error.log, I could see a django exception saying it couldn't find the 404.html.

This made no sense to me at all. Why would it be looking for a 404.html when it doesn't need it yet (the flatpage middleware should have intercepted it before it looked for a 404.html template, was my thinking). It was suggested to me in the irc channel that I create a 404.html (for more reasons that just fixing this problem).

So to just test that theory, I ran touch templates/404.html -- it worked!