Package: django-wysiwyg
Table of ContentsInstallationConfigurationUsing the CKEditorUsing TinyMCEOther editorsUsageWithin your pagesWithin Django AdminHandling ContentCleaning HTMLTo display raw HTMLA Django application for easily converting HTML <textarea>s into rich HTML
editors that meet US Government 508/WAC standards. This application has been
demonstrated to work just fine with django-crispy-forms
(https://github.com/maraujop/django-crispy-forms).Currently this works as a template tag. We did it this way because control of
how editing works is arguably a template issue (i.e. presentation) and not a
forms/model issue (i.e. control).YUI is the default editor due to familiarity, accessiblity and the fact that
it’s possible to run with entirely off of Yahoo’s CDN, avoiding the need to
maintain any local resources. CKEditor can be used but will require you to
install the CKEditor files in STATIC_URL/ckeditor (see below).If you want to contribute to django-wysiwyg, please do so from the repository
athttp://github.com/pydanny/django-wysiwyg.Note: This may be obvious, but this only works on<textarea>(models.TextField) and not simple character (<input>) fields.InstallationVia pip:pip install django-wysiwygConfigurationAdd‘django_wysiwyg’to yourINSTALLED_APPSinsettings.py:INSTALLED_APPS = (
    ...
    'django_wysiwyg',
)Using the CKEditorIf you wish to use CKEditor set the flavor insettings.py:DJANGO_WYSIWYG_FLAVOR = "ckeditor"Please note that doing so requires you to make sure the CKEditor distributables are available.
You can either:place the ckeditor distributables underSTATIC_URL/ckeditorinstalldjango-ckeditorand include it in theINSTALLED_APPSsetDJANGO_WYSIWYG_MEDIA_URLinsettings.pyto the appropriate location containing the ckeditor distribution.Using TinyMCETo use TinyMCE, use the following settings:DJANGO_WYSIWYG_FLAVOR = "tinymce"    # or "tinymce_advanced"The TinyMCE distributables need to be available. You can either:place them inSTATIC_URL/tinymceinstalldjango-tinymceand include it in theINSTALLED_APPSsetDJANGO_WYSIWYG_MEDIA_URLto the appropriate location.Other editorsThe following values are allowed for theDJANGO_WYSIWYG_FLAVORsetting:ckeditor- TheCKEditor, formally known as FCKEditor.redactor- TheRedactoreditor (requires a license).froala- TheFroalaeditor (requires a license).tinymce- TheTinyMCEeditor, in simple mode.tinymce_advanced- TheTinyMCEeditor with many more toolbar buttons.yui- TheYAHOOeditor (the default)>yui_advanced- TheYAHOOeditor with more toolbar buttons.alloyeditor- TheAlloyEditor, a modern editor based on CKEditorOther editors can be supported by providing the required templates;
seehttp://django-wysiwyg.readthedocs.org/en/latest/extending.htmlUsageWithin your pagesThere are two template tags:wysiwyg_setupmust be called once per page,
preferably in the <head>, to load the JavaScript dependencies.wysiwyg_editorshould be called once per text area, after the text area has
been created. A simple example:{% load wysiwyg %}
{% wysiwyg_setup %}

<textarea id="foo"></textarea>

{% wysiwyg_editor "foo" %}Within Django Admindjango-wysiwyg comes with a custom file that serves as a base template for
alterations to admin displays. To make an admin field display rich text, do
the following:In your custom app’s admin.py file, on the MyModelAdmin class, addchange_form_template ='my-app-name/admin/change_form.html'. For example:from django.contrib import admin
from fun.models import Playground

class PlaygroundAdmin(admin.ModelAdmin):
    change_form_template = 'fun/admin/change_form.html'

admin.site.register(Playground, PlaygroundAdmin)copydjango_wysiwyg/templates/my-app-name/admin/change_form.htmltomy_app/templates/<my-app-name>/admin/change_form.html. For example:cp django_wysiwyg/templates/my-app-name/admin/change_form.html pydanny/templates/fun/admin/change_form.htmlNow open the newpydanny/templates/my-app-name/admin/change_form.htmlfile. You
will need to set the fields you want made into rich text editors by adding
{% wysiwyg_editor “id_description” %} template tag calls, replacing
“id_description” with whatever your form’s HTML field is named. For
example:{% extends "admin/change_form.html" %}

{% load wysiwyg %}

{% block extrahead %}
    {{ block.super }}
    {% wysiwyg_setup %}
{% endblock %}

{% block content %}
    {{ block.super }}
    {% wysiwyg_editor "id_description" %}
{% endblock %}Handling ContentCleaning HTMLdjango_wysiwyg.clean_html will be exported if you have either html5lib
(http://code.google.com/p/html5lib/) or pytidylib installed. Both should
install with pip or easy_install, although the later will require having the
htmltidy C library installed.Using clean_html in views is simple:data = django_wysiwyg.clean_html(data)To display raw HTMLIn your templates:{% autoescape off %}
    {{ content }}
{% endautoescape %}or:{{ content|safe }}This should not be used without careful consideration if your content comes
from untrusted usersclean_htmldoes not protect against security problems;sanitize_htmlattempts to do so but is only available with html5lib (tidylib has no
equivalent mode) and should currently be considered experimental.