Flourish API: flourish.generators

The generators in Flourish are responsible for turning one or more source objects into output HTML.

Subclassing the generators

If you need to alter the way a page or pages are being generated, it should normally be possible to subclass one of the default generators and modify only a small part of it.

The included generators

The included mixins

PageContextMixin

Adds the first of self.source_objects to the template context as page as well as all key values from that object. For example, a TOML source of:

title = 'About this site'
tag = ['about', 'information']
noindex = true

would make all of {{page}}, {{title}}, {{tags}}, and {{noindex}} values available for use in templates.

PageIndexContextMixin

Adds the list of source objects to the template context as pages.

Stopping generation

Sometimes you may want to not generate a page (for example, due to a lack of content). To do this, raise DoNotGenerate and the generator will skip that page without it counting as an error.

def get_objects(self, tokens):
    sources = self.get_filtered_sources().filter(**tokens)
    if sources.count() == 0:
        raise self.DoNotGenerate