Adding Rich Text Editor Tiny MCE to Django Admin for Flat Pages


Using django-flatpages-tinymce to enhance Django's flat pages

Published on by nick

Tags: django, flatpages, tinymce

While reading Practical Django Projects, by James Bennett, I decided to implement several of those features highlighted in the book.

This particular article outlines the steps to take to get TinyMCE implemented in a newer version of Django, 1.5, and its flatpages. The version in the book (book was published in 2008) is quite old and much has changed since then.

Instead of downloading and installing manually, you can actually do most of the TinyMCE integration with existing projects and applications. For example, I used django-flatpages-tinymce.

To get started, we need to install a couple packages:

pip install django-flatpages-tinymce
pip install django-tinymce

Next, according to the django-flatpages-tinymce documentation, you add these bits to your configuration:

Django settings.py file:

INSTALLED_APPS = (
    ...
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
    ...
    'tinymce',
    'flatpages_tinymce',
)

MIDDLEWARE_CLASSES = (
    ...
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

The projects urls.py file:

urlpatterns = patterns('',
    ...
    # tinymce
    url(r'^tinymce/', include('tinymce.urls')),
    ...
)

Finally, to synchronize the database and collect your static files, run this command:

python manage.py syncdb
python manage.py collectstatic

This should do it. Now to actually get TinyMCE to show up in your flat pages content section, you need to tell Django's templates to use it. I created a directory in my templates folder called admin/flatpages/flatpage and then copied the change_form.html file from the Django admin template directory located at django/contrib/admin/templates/admin. In this file, you need to add this line:

{% load flatpage_admin %}

If all goes well, you should see the rich text editor in your flat page admin section.

Comments

Comments powered by Disqus

 Blog Search

  Popular Tags

django, ubuntu, mod_wsgi, apache, authentication, python, tls, linux, forms, ssl, virtualenv, dell, uwsgi, bash, nginx, raid, customer-service, centurylink, ux, software-companies, rais, form, centos, password, certificates, tinymce, mdadm, dual-boot, file-server, virtualhost, gluster, IT, blog, get, networking, piplight, distributed-file-system, big companies, bitnami, cygwin, windows, samba, scripting, pygments, post, programming-language, ui, lampstack, outsourcing, isp, security, usabillity, provision, php, shared-hosting, netflix, git, flatpages, syntax-highlighting, virtualbox, hg, redirect, usability, prg, acls, change-password, complex, view tags...

 Questions/Comments?

Drop me a line... [email protected]
Follow me on Twitter... @nicorellius
Share on Facebook...