How to enable the rich editor in Django?

196 views
Skip to first unread message

TualatriX

unread,
Mar 22, 2008, 1:18:22 AM3/22/08
to Django users
Hi:

I'm a django beginner, in my test project, I want to enable the rich
editor of the TextField.
So I search for some articles, I choose to use tinymce. I do the
steps following the tutorial on djangoproject.com, but failed. The
tutorial is:
http://code.djangoproject.com/wiki/AddWYSIWYGEditor

I'm using ubuntu 7.10, and installed the tiny_mce in :
/usr/lib/python2.5/site-packages/django/contrib/admin/media/js/
tiny_mce

In my project's Setting.py, the ADMIN_MEDIA_PREFIX is /media/ by
default.
I wrote textareas.js in /usr/lib/python2.5/site-packages/django/
contrib/admin/media/js/tiny_mce, and modified the article model, added
the lines:
class Admin:
js = (
'/media/js/tiny_mce/tiny_mce.js',
'/media/js/tiny_mce/textareas.js',
)

Then I ran the server by: python manage.py runserver. And went to
admin to edit, but the textareas is still like this: no tiny_mce
there.
And there's nothing error message such as 404.
Here's the output:
[22/Mar/2008 13:10:06] "GET / HTTP/1.1" 200 606
[22/Mar/2008 13:10:08] "GET /articles/2 HTTP/1.1" 301 0
[22/Mar/2008 13:10:08] "GET /articles/2/ HTTP/1.1" 200 566
[22/Mar/2008 13:10:09] "GET /admin/article/article/2 HTTP/1.1" 301 0
[22/Mar/2008 13:10:09] "GET /admin/article/article/2/ HTTP/1.1" 200
4661
[22/Mar/2008 13:10:09] "GET /admin/jsi18n/ HTTP/1.1" 200 80

I try to make up a "media" dir in the project's root folder, the
effect is the same. But when I made the js tuple as an error path,
such as " '/adfamedia/js/tiny_mce/tiny_mce.js', the 404 will take
place.

Can anyone help me?
Thanks.

Michael

unread,
Mar 22, 2008, 11:20:45 AM3/22/08
to django...@googlegroups.com
I am not quite sure how you have this set up, but because you are
running on the development server what directory do you have being
served with django.views.static.serve? Inside that directory there
should be a media folder where I generally copy or link the
contrib/media files. What version of Django are you using? You should
have your media directory set up (not admin media) and that follows
the path that you gave your tuples.

So in your example if you media directory was /var/www/ you have in
your urls (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/var/www'}),
You then add your admin media to that directory so if you are using
media for your admin media all of contrib/admin/media should be in
/var/www/media.

From here you add your js for tinymce so the path would be from your
example /var/www/media/js/tiny_mce/tiny_mce.js and
/var/www/media/js/tiny_mce/textareas.js

Just as a best practice I wouldn't put the tinymce script into my
admin media area because that is liable to be updated and you don't
want to acciddentally overwrite "core" javascript. If you follow the
example it has you putting the scripts into other folders.

Hope that helps,

Michael

TualatriX

unread,
Mar 23, 2008, 3:27:07 AM3/23/08
to Django users
Thank you very much. Michael.
I've set the url (r'^site_media/(?P<path>.*)$' to my case, so it
works.

And thanks of your advice, now I separated the tinymce script from
admin media.

On 3月22日, 下午11时20分, Michael <newmani...@gmail.com> wrote:
> I am not quite sure how you have this set up, but because you are
> running on the development server what directory do you have being
> served with django.views.static.serve? Inside that directory there
> should be a media folder where I generally copy or link the
> contrib/media files. What version of Django are you using? You should
> have your media directory set up (not admin media) and that follows
> the path that you gave your tuples.
>
> So in your example if you media directory was /var/www/ you have in
> your urls (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
> {'document_root': '/var/www'}),
> You then add your admin media to that directory so if you are using
> media for your admin media all of contrib/admin/media should be in
> /var/www/media.
>
> From here you add your js for tinymce so the path would be from your
> example /var/www/media/js/tiny_mce/tiny_mce.js and
> /var/www/media/js/tiny_mce/textareas.js
>
> Just as a best practice I wouldn't put the tinymce script into my
> admin media area because that is liable to be updated and you don't
> want to acciddentally overwrite "core" javascript. If you follow the
> example it has you putting the scripts into other folders.
>
> Hope that helps,
>
> Michael
>
Reply all
Reply to author
Forward
0 new messages