muhuk
muhuk

Reputation: 16085

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

Why I don't need the model FlatPage

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?

Upvotes: 6

Views: 1352

Answers (1)

Daniel Naab
Daniel Naab

Reputation: 23066

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 %}

Upvotes: 9

Related Questions