Using django-flatpages-tinymce to enhance Django's flat pages
Published on by nick
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.
Drop me a line...
[email protected]
Follow me on Twitter...
@nicorellius
Share on
Comments
Comments powered by Disqus