views:

458

answers:

2

The Django flatpages app has a well-known and oft-discussed-on-the-web bug related to a missing 404.html "Page Not Found" template in your project's templates directory. If you have DEBUG = False in your settings.py file, and you're missing the 404.html file, flatpages will generate a 500 server error instead of loading the flatpage because the project tries to find the 404.html template, and the 500 is generated because it isn't there.

My problem is different than this. I do have a 404.html in my templates directory, hooked into my project, the Middleware is hooked up, the SITE_ID is correct for each flatpage, and the templates/flatpages/default.html file exists.

When I try to load any flatpage, I get my custom 404.html error page returned to me. So, the 404 template is working, but the flatpage middleware doesn't seem to be checking the URLs in the flatpage models before it falls back on the 404.

Has anyone else experienced this and/or found a solution? This is a beta version, so perhaps a solution is in the works as I type. I'm using Django 1.1 beta 1.

Here is my entire MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', 'djangodblog.DBLogMiddleware', 'ecomstore.SSLMiddleware.SSLRedirect', 'ecomstore.marketing.urlcanon.URLCanonicalizationMiddleware', 'django.contrib.redirects.middleware.RedirectFallbackMiddleware', )

A: 

I had a similar problem today. After a lot of chekcing I finally fixed it by turning on "Enable comments" (in the admin interface) for the flatpage in question...

On page http://www.petersanchez.com/2007/08/19/django-flatpages-wtf/ Peter Sanchez lists 4 checks to do, but it did not help in my case.

Peter Mortensen
Hello Peter, I tried "Enable comments" for my three flatpages and it didn't fix the issue for me. I also came across that post before and it didn't help me either. Thanks for sharing.
Jim McGaw
+1  A: 

I browsed flatpage sources and solved same problem by adding slash to the end of the page url in admin area. Maybe it will help you.

haha lol, true that. i wasted an hour right now solving this bug. i had to prepend also a slash. thanks for the tip
zalew