Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django.contrib.flatpages without models

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?

like image 410
muhuk Avatar asked Dec 06 '08 21:12

muhuk


Video Answer


1 Answers

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 %}
like image 117
Daniel Naab Avatar answered Sep 27 '22 20:09

Daniel Naab