A flexible item type for django-flexible-content that implements a CKEditor
Because django-flexible-content
is designed to be as minimal as possible, its default set of item types was never meant to satisfy everyone. I designed this plugin for my own use, for obvious reasons: sometimes plain text isn't featureful enough, and HTML isn't a user-friendly option.
It allows user-friendly input of basic text:
- paragraphs
- bold, italic, underline
- lists
- links (these can be configured)
Other than implementing CKEditor within the admin, it also prevents fully-qualified domain names from making it into the database when those domains reference the current site. This allows your production database (www.mydomain.com) to work seamlessly on sites with other domains. It finds these domains via Django's Sites framework, or alternatively by a small addition to your settings file.
Coming soon: In addition, the underlying CKEditorField itself can optionally clean the submitted HTML, removing all tags except those above. So if you want to strip outside styles and tags at all cost, it can do that. Alternatively, if you want to leave room for small HTML tweaks, you can disable this as well.
It intentionally doesn't support uploading images or files. One of the ideas behind django-flexible-content
was that those things are style-able and well-managed on the back-end.
A few examples:
- If you want to display an image or download with a heading above it, a caption below it, or a description next to it, your image type can support that. A WYSIWYG editor almost never could.
- If you have the same PDF or image uploaded in 18 different places, you can choose how to handle that in your image type (offer a list of existing files; detect duplicate uploads and point all those references to a single version of the file).
Technically, you could manually link to an uploaded file, or reference an image in the raw HTML... oh well.
Install the package:
pip install django-flexible-content-ckeditor
Update the project's settings to include the package in
INSTALLED_APPS
:INSTALLED_APPS = ( # your other apps here # ... 'flexible_ckeditor', )
Update the project's settings to include the new CKEditor flexible item type:
FLEXIBLE_CONTENT = { 'ITEM_TYPES': ( 'flexible_ckeditor.CKEditorText', # You'll probably want to include some of the default item types, # if you hadn't configured FLEXBILE_CONTENT['ITEM_TYPES'] yet. 'default_item_types.Download', 'default_item_types.Image', 'default_item_types.Video', ), }
Restart your server and go!
Yes! Though the editor may be trimmed down, it can be used to support basic formatting on arbitrary models, outside of django-flexible-content
's content areas:
from django.db import models from flexible_ckeditor.fields import CKEditorField class Person(models.Model): name = models.CharField(max_length=100) bio = CKEditorField()
Note that it'll still abide by the settings defined in FLEXIBLE_CONTENT['ckeditor']
, such as whether or not to clean the HTML upon submission.