Wednesday 20 February 2013

Solved [No FlatPages matches the given query] #Django

After following most of the solutions provided, the most important factor you should consider that is not indicated in the django docs is that of SITE_ID = 1.

By default Django provides on the admin panel for Sites, "example.com" . When adding flatpages one may tend to add his own site and most tutorials will dictate that you use SITE_ID = 1 on settings.py .

What the don't tell you is that "example.com" site is by default 1. SO what you should do is edit the "example.com" site to 127.0.0.1:8000 and there you have it.

Remember to also add
url.py

    # last entry in urls.py. 
(r'', include('django.contrib.flatpages.urls')),

settings.py`

    MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
   
)

    INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
   
)

2 comments:

  1. Oh, thank you, thank you, thank you! I was stuck on this for a long time. Editing example.com in the sites table to 127.0.0.1:8000 did it for me.

    ReplyDelete
  2. The problem also disturbed for more than a week and I decided to write this post because I noted there was no docs about it

    ReplyDelete