0

I'm using django 1.1.3 and following along with a book called Practical Django Projects. I'm running into a problem editing the .urls file in my project folder and while creating a flat page on the admin site for my project. This is what I have in my urls file:

urlpatterns = patterns('',
    # Example:
    # (r'^cms/', include('cms.foo.urls')),

    # Uncomment the admin/doc line below and add #'django.contrib.admindocs' 
    #to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),

(r'', include('django.contrib.flatpages.urls')),


)

I have created a flat page name with the url extension /first-page/ . When I navigate to it i receive PAGE NOT FOUND No FlatPage matches the given query. What I should be seeing according to my book is TemplateDoesNotExist at /first-page/ with a wealth of other error messages.

I'm not sure what I'm doing incorrectly as I followed the book's instructions to the letter (I think). If I haven't provided enough information please let me know. I'm not sure at this point what else I would include.

Thank you ahead of time for any help.

Bodhidarma
  • 519
  • 1
  • 7
  • 25
  • Have you created the directory flatpages/default.html and configured the template directory in settings.py? Btw: are you sure about the Django version? Seems very old to me. – het.oosten May 22 '15 at 12:26
  • I'm sure about the version. I'm using it to go along with the book which is an older book. I didn't create such a directory or configured the template directory as the book does not recommend doing so. My expectations are to see TemplateDoesNotExist at /first-page/ when navigating to the page. – Bodhidarma May 22 '15 at 12:32
  • Have you tried /first-page and /first-page/ ? – het.oosten May 22 '15 at 13:01
  • Also check the site_id setting. See this topic: http://stackoverflow.com/questions/8144279/django-error-no-flatpage-matches-the-given-query – het.oosten May 22 '15 at 13:11

1 Answers1

1

You have not created the default.html file. Flatpages look for a template named default.html. Here they insert their content. As you have not provided that file so flatpages raise the complaint for template does not exist.

To solve your problem follow these steps.

  1. Create a directory for templates in your project. Name it "templates".
  2. In "templates" directory create a directory named "flatpages".
  3. In "flatpages" directory create an html file named "default.html".

Graphically it would look something like this:

enter image description here

  1. Now in default.html enter the following
<!DOCTYPE html>
<html>

<head>
  <title>{{ flatpage.title }}</title>
</head>

<body>
  <h1>{{ flatpage.title }}</h1>
  {{ flatpage.content }}
</body>

</html>
  1. Now in your settings file change the value of "TEMPLATE_DIRS" to point to this "templates" directory. It will look something like this:
TEMPLATE_DIRS = (
    "/home/wasim/so/sopro/templates",
    # Above insert your path
)

Replace the above path with your path for templates directory. Now run the server and it will work.

zkk
  • 207
  • 1
  • 8