I would like to know the best way to replace a standard textarea field with a rich text editor in Django Admin?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
At the date of the post and the answers TinyMCE was quite popular (as it probably remains today). But after some time ckeditor has appeared and many consider that a better alternative, including many SO users:
Compare TinyMCE and CKeditor for a Wiki
http://www.turnkeylinux.org/blog/tinymce-vs-ckeditor
There is also a 2013 review of WISIWYG editors with Django in Russian:
http://habrahabr.ru/company/htdt/blog/202782/
I'd say: define your own ModelAdmin class and overwrite the widget used for particular field, like:
(AdminWYMEditor is a
forms.Textarea
subclass that adds WYMEditor with configuration specific to Django admin app).See this blog post by Jannis Leidel to see how this widget can be implemented.
Take a look on this snippet - basic idea is to include custom JS in your admin definitions which will replace standard text areas with rich-text editor.
For jQuery/FCKEditor such JS could look like that:
There's an add-on Django application to provide TinyMCE support for Django admin forms without having to muck around with admin templates or Django newform internals.
Ok, to update a little this post, I would say that the easiest way to implement TinyMCE is to use the django-tinymce app. You must also download the JS files from the TinyMCE page. I got some errors with the django intenationalization, but downloading the laguage packs from the TinyMCE must be enough.