6

I have some flatpages with empty content field and their content inside the template (given with template_name field).

Why I am using django.contrib.flatpages

  • It allows me to serve (mostly) static pages with minimal URL configuration.
  • I don't have to write views for each of them.

Why I don't need the model FlatPage

  • I leave the content empty and just supply a template path. Therefore I can take advantage of having the source in a file;
    • I can edit the source directly from the file system, without the help of a server (such as admin).
    • I can take advantage of syntax highlightning and other editor features.
  • With the model I have to maintain fixtures for flatpages.
    • So the data for the same entity is in two seperate places.
    • If I move the content inside the fixture it'll be more difficult to edit.
      • Even if fixture maintenance was a non-issue I'd still need to dump and load these fixtures again and again during development.

What I am looking for

Basically; getting rid of FlatPage model while maintaining contrib.flatpages functionality. I don't have a clear idea how this should be solved. If there's a clean way of modifying (like add_to_class) FlatPages to get the information somewhere other than the database I'd prefer that. Maybe the metadata can be inserted to the templates and then a special manager that reads this data would replace the default manager of FlatPages.

If I don't prefer manual editing over admin functionality for flatpages, how can take the database out of the equation?

muhuk
  • 15,777
  • 9
  • 59
  • 98
  • You have the wrong expectation about what a flat page is for. It is for "rarely edited" content that needs to be accessible via the admin or forms so an administrator or content provider can modify them should, say, contact information change for a site. – Soviut May 11 '09 at 07:05

1 Answers1

9

Using the direct_to_template generic view would be a lot simpler. You could use the passed in parameters on one view to specify the actual template in urls.py, if you don't want to add an entry for each page:

r'^foo/(?P<template_name>.+)/$','direct_to_template', {'template': 'foo_index.html'}),

Then import the template in your foo_index.html:

{% include template_name %}
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
Daniel Naab
  • 22,690
  • 8
  • 54
  • 55
  • direct_to_template is the way to go for me. I guess I was expecting too much from flatpages. I have some tagging and more than one block in my templates. Thanks. – muhuk Dec 07 '08 at 17:35