Getting a ‘No FlatPage matches the given query’ error?
This may be useful if you are a Django newb. All others… this will probably be gibberish.
Are you are working through James Bennett’s ‘Practical Django Projects’ (second edition) and getting the above error when trying to view your first flatpage? This could be because you did not put leading and trailing forward slashes in the flatpage URL field when setting up your flatpage in the admin panel.
The book actually tells you to do this in the example it gives, but in my speed-reading I ignored the slashes and treated the URL field as though I was entering a wordpress page slug. Four hours, a django reinstall, and much angst later, I have relearned the lesson that it always pays to read the instructions carefully.
Perhaps you can avoid my mistake.
_______
Short URL for this post: http://wp.me/pnqr9-P

Paul 23:43 on Saturday, August 15, 2009 Permalink
I have put the slashes but still throwing the same error!!
/first-page/
Ben 16:24 on Monday, August 17, 2009 Permalink
Hmmm. When I was hunting around I saw a couple of other possible causes for this, but I suspect you’ve already come across those. From memory I eventually found the source of my problem by playing around in the admin panel – after changing the page title a few times and trying to view the page from the admin panel I realised django wasn’t rendering the url correctly. That at least narrowed it down to a pattern/url problem rather than there being no communication with the flatpage ap at all. Maybe a similar approach would help you narrow down the source of your issue.
Raj 13:14 on Thursday, May 27, 2010 Permalink
That was totally it! Thanks!
Scott Crosby 2:57 on Saturday, June 12, 2010 Permalink
Thanks! You saved me hours :-)
Michael 16:06 on Thursday, July 15, 2010 Permalink
I just came across your post and found a different problem with the same symptoms, so I wanted to post a comment to help out anyone in the future who stumbles across this: I received the same error because I had added “127.0.0.1:8000″ as a separate site, rather than editing “example.com”, so my site ID was 2, rather than 1. Instead of modifying my settings.py file to have SITE_ID = 1, I went to the shell and changed the localhost site to have an id of 1, and then it worked.
Duy 19:29 on Tuesday, October 26, 2010 Permalink
Ha! Thanks a lot. This is what I’m looking for!
Srinivasa 1:30 on Friday, December 10, 2010 Permalink
Solution provided by Machael and Ben works in different scenarios, but they are right. Thank you for the solution. This will help people who ignore few things while reading the ‘Practical Django Projects’ second edition.
Patrick 22:05 on Wednesday, February 9, 2011 Permalink
After days of debugging and trying to figure out why “get_object_or_404()” in django/contrib/flatpages/views.py was returning “No FlatPage matches the given query” I stumbled across this page. Thank you! Why is flatpages not more forgiving! (why does it not just append a slash if it doesn’t exist!!)
Ben 7:28 on Thursday, February 10, 2011 Permalink
Glad it helped Patrick. I’ve not looked at what it does for this sort of error, but you can add APPEND_SLASH = True to your settings.py to auto-append trailing slashes to incoming urls. This will only work if you have django.middleware.common.CommonMiddleware installed in your middleware settings, but it might sort out the slash-sensitive flatpage issue.
Nai 21:49 on Friday, March 4, 2011 Permalink
Had the same problem, different solution. I had to add ‘django.contrib.flatpages.middleware.FlatpageFallbackMiddleware’, to my middleware in settings.py
Hope this helps someone too
Mark Andrews 10:57 on Saturday, July 23, 2011 Permalink
thanks, man! that was driving me nuts!
Vitalii 23:57 on Sunday, August 28, 2011 Permalink
Very, very, very big THANKS to Michael!!!!!
Nima 6:41 on Saturday, December 3, 2011 Permalink
Hi
I have same problem
I set SITE_ID to 1
and also delete example.com
and I am sure about slashes :)
but still same problem :(
mert ozcan 3:48 on Sunday, January 15, 2012 Permalink
I realized the book is not clear about the directory where we should place default.html file..
Its basically like this.. ..cms/first-page/flatpages/default.html
tipler 9:03 on Thursday, August 23, 2012 Permalink
Hi everybody!
The correct solution is here:
http://stackoverflow.com/questions/9934969/django-urlpatterns-order
Regards!
Jason 13:37 on Sunday, November 4, 2012 Permalink
Thanks Nai, your comment is what ultimately solved my issue !
Emmanuel Fleurine 2:58 on Friday, December 21, 2012 Permalink
J’ai trouver le probleme c’est SITE_ID
exemple.com = SITE_ID 1
mais quand on efface exemple.com et qu’on cree un autre site le nouveau site n’a pas un ID de 1 mais de 2 donc il faut aller dans le fichier de configuration et change le ID du site en 2 ou dans le numero qui convient
et pour trouver le ID du site que vous etes si vous avez cree plusieurs alors il faut aller dans
Home —>>>>> SItes —>>>> Cliquer sur le site en question comme si vous vouliez le modifier
vous verrez un numero dans la barre d’addresse et ce numero sera l’ID de votre site.
Vous pouvez pas imaginer combien je suis heureux d’avoir trouver une partie de la solution vraiment.
J’ai suer un mois
X 10:10 on Monday, January 14, 2013 Permalink
Thank you Emmanuel !!!