The flatpage page type

The flatpage provides a simple page type with a WYSIWYG (“What You See is What You Get”) editor.

../_images/flatpage-admin.png

The WYSIWYG editor is provided by django-wysiwyg, making it possible to switch to any WYSIWYG editor of your choice.

Note

This page type may seem a bit too simply for your needs. However, in case additional fields are needed, feel free to create a different page type yourself. This page type can serve as canonical example.

Installation

Install the dependencies via pip:

pip install django-fluent-pages[flatpage]

This installs the django-wysiwyg package.

Add the following settings to settings.py:

INSTALLED_APPS += (
    'fluent_pages.pagetypes.flatpage',
    'django_wysiwyg',
)

Using CKEditor

To use CKEditor, install django-ckeditor:

pip install django-ckeditor

Add the following settings to settings.py:

INSTALLED_APPS += (
    'ckeditor',
)

DJANGO_WYSIWYG_FLAVOR = "ckeditor"

Using TinyMCE

To use TinyMCE, install django-tinymce:

pip install django-tinymce

Add the following settings to settings.py:

INSTALLED_APPS += (
    'tinymce',
)

DJANGO_WYSIWYG_FLAVOR = "tinymce"    # or "tinymce_advanced"

Using Redactor

To use Redactor, tell django-wysiwyg where to find the static files. This is done on purpose to respect the commercial license.

DJANGO_WYSIWYG_FLAVOR = "redactor"
DJANGO_WYSIWYG_MEDIA_URL = "/static/vendor/imperavi/redactor/"

Template layout

To integrate the output of the page into your website design, overwrite fluent_pages/base.html. The following blocks have to be mapped to your website theme base template:

  • title: the sub title to display in the <title> tag.
  • content: the content to display in the <body> tag.
  • meta-description - the value of the meta-description tag.
  • meta-keywords - the value for the meta-keywords tag.

In case your website base template uses different names for those blocks, create a fluent_pages/base.html file to map the names:

{% extends "pages/base.html" %}

{% block head-title %}{% block title %}{% endblock %}{% endblock %}

{% block main %}{% block content %}{% endblock %}{% endblock %}

Further output tuning

The name of the base template can also be changed using the FLUENT_PAGES_BASE_TEMPLATE setting. The page type itself is rendered using fluent_pages/pagetypes/flatpage/default.html, which extends the fluent_pages/base.html template.

Configuration settings

The following settings are available:

DJANGO_WYSIWYG_FLAVOR = "yui_advanced"

FLUENT_TEXT_CLEAN_HTML = True
FLUENT_TEXT_SANITIZE_HTML = True

DJANGO_WYSIWYG_FLAVOR

The DJANGO_WYSIWYG_FLAVOR setting defines which WYSIWYG editor will be used. As of django-wysiwyg 0.5.1, the following editors are available:

  • ckeditor - The CKEditor, formally known as FCKEditor.
  • redactor - The Redactor editor (requires a license).
  • tinymce - The TinyMCE editor, in simple mode.
  • tinymce_advanced - The TinyMCE editor with many more toolbar buttons.
  • yui - The YAHOO editor (the default)
  • yui_advanced - The YAHOO editor with more toolbar buttons.

Additional editors can be easily added, as the setting refers to a set of templates names:

  • django_wysiwyg/flavor/includes.html
  • django_wysiwyg/flavor/editor_instance.html

For more information, see the documentation of django-wysiwyg about extending django-wysiwyg.

FLUENT_TEXT_CLEAN_HTML

If True, the HTML tags will be rewritten to be well-formed. This happens using either one of the following packages:

FLUENT_TEXT_SANITIZE_HTML

if True, unwanted HTML tags will be removed server side using html5lib.