Monday, June 01, 2009

404 Errors with Django flatpages

In a Python class I'm teaching, I had the students do the Django tutorial with some added bits. One of the added bits was to add an About page using Django flatpages. A couple of students had problems where they were getting 404 errors even though there was a flat page defined at the /about/ URL.

I had one student zip up his project (including his sqlite database) and send it to me. (One of the other "added bits" was that they had to create portable projects - no hardcoded paths in settings.py.) When I first ran his project, sure enough - 404. I poked around, and everything looked good. Then, I used manage.py loaddata to load my data (including a flat page) into his DB, and it all worked fine. So, it was a data issue, not a project-level mis-configuration.

After reading a comment from another student about this problem, I looked into the database using SQLite Manager, where I could see that the flat page was assigned with site_id #3, not the default #1, and somewhere along the line he had created multiple sites in his DB. I looked in settings.py, and sure enough, SITE_ID referred to site #1, not #3 As noted in the flat pages docs, this needs to match (under some circumstance). Changing that, fixed it all up with the students original data.

If you have been having this problem, I am hopeful that the Google sent you here, and you can see how to fix it.

enjoy,
Charles.

8 comments:

Alex said...

Thanks, this helps me a lot.

ricardo said...

Thank you very much for sharing such information. I was facing the exactly same problem and that worked perfectly.

Thank you!

Charles Anderson said...

No problem - that's why I post these particular things: I had the problem, I'm sure someone else will, too.

Unknown said...

Thank you very much! Your post was very helpful to me. ^^

Mike Casey said...

Mate thanks a mill, that was really getting to me. Was not easy for me to solve so ended up dropping tables and running synchdb again and then starting again from scratch.

Eileen said...

Yes, thanks, I had set site id to today's date, 20120101, thinking that would be a good unique number for my sites .. wow, I would have looked awhile to figure this out

Eileen said...

Perfect, thanks!

Charles Anderson said...

No problem. Glad I could help.
Charles.