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:

18 thoughts on “Getting a ‘No FlatPage matches the given query’ error?

  1. 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.

  2. 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 “” as a separate site, rather than editing “”, so my site ID was 2, rather than 1. Instead of modifying my 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.

  3. 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.

  4. After days of debugging and trying to figure out why “get_object_or_404()” in django/contrib/flatpages/ 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!!)

  5. 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 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.

  6. Had the same problem, different solution. I had to add ‘django.contrib.flatpages.middleware.FlatpageFallbackMiddleware’, to my middleware in

    Hope this helps someone too

  7. 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

  8. J’ai trouver le probleme c’est SITE_ID = SITE_ID 1
    mais quand on efface 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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s