Django.contrib.flatpages without models

I have several flatpages with an empty content field and their contents inside the template (set in the template_name field).

Why am I using django.contrib.flatpages

  • It allows me to serve (mostly) static pages with minimal URL configuration.
  • I do not need to write submissions for each of them.

Why I Don't Need a FlatPage Model

  • I leave the contents empty and just set the template. Therefore, I can use the source in the file;
    • I can edit the source directly from the file system without the help of a server (e.g. administrator).
    • I can use syntax highlighting and other editor features.
  • With the model I have to support fixtures for flatpages.
    • Thus, the data for the same object are in two different places.
    • If I move the contents inside the device, it will be harder to edit.
      • Even if maintenance was not a problem, I would still have to reset and load these lights again and again during development.

What i'm looking for

Basically; get rid of the FlatPage model while maintaining the functionality of contrib.flatpages . I have no clear idea of ​​how this should be resolved. If there is a clean way to modify (e.g. add_to_class ) FlatPages to get information somewhere other than the database, I would prefer this. Perhaps metadata can be inserted into templates, and then a special manager who reads this data will replace the default manager of FlatPages .

If I do not prefer manual editing over admin functions for flatpages, how can I deduce the database from the equation?

+6
python django templates django-flatpages
source share
1 answer

With direct_to_template overall look will be much simpler. You can use the passed parameters in one view to indicate the actual template in urls.py if you do not want to add an entry for each page:

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

Then import the template into your foo_index.html :

 {% include template_name %} 
+9
source share

All Articles