TinyMCE config

282 views
Skip to first unread message

jondbaker

unread,
Aug 1, 2012, 9:19:28 PM8/1/12
to django...@googlegroups.com
I'm trying to install django-tinymce so that I can use utilize it within the admin when editing flatpages and flatblocks. I've been following the instructions at http://django-tinymce.readthedocs.org/en/latest/installation.html, but I can't seem to get TinyMCE to display. django-tinymce has been installed via pip, and here are the relevant snippets of code:

settings.py
INSTALLED_APPS = (
    ...
    'tinymce',
)
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
TINYMCE_JS_URL = os.path.join(PROJECT_ROOT, 'templates/static/js/tiny_mce/tiny_mce.js')
TINYMCE_JS_ROOT = os.path.join(PROJECT_ROOT, 'templates/static/js/tiny_mce')
* I have a hunch that here is where I'm going wrong. The instructions indicate that the tiny_mce js dir should reside in MEDIA, but I was under the impression that MEDIA is to be used for user-uploaded content, while STATIC is for assets like JS and CSS. That's why I put the tiny_mce lib in STATIC instead of MEDIA.

urls.py
urlpatterns = patterns(''
    ...
    url(r'^tinymce/', include('tinymce.urls')),
)
* If i visit 'http://127.0.0.1:8000/tinymce/flatpages_link_list/' in the browser, 'var tinyMCELinkList = []' is rendered.

Any help would be greatly appreciated. Thanks.

Mike Dewhirst

unread,
Aug 1, 2012, 9:59:23 PM8/1/12
to django...@googlegroups.com
On 2/08/2012 11:19am, jondbaker wrote:
> I'm trying to install django-tinymce so that I can use utilize it within
> the admin when editing flatpages and flatblocks. I've been following the
> instructions at
> http://django-tinymce.readthedocs.org/en/latest/installation.html, but I
> can't seem to get TinyMCE to display. django-tinymce has been installed
> via pip, and here are the relevant snippets of code:
>
> *settings.py*
> INSTALLED_APPS = (
> ...
> 'tinymce',
> )

I have tinyMCE working and no mention of it in settings.py. It isn't a
Django app.

It needs to be served by your web server eg Apache. The important thing
is to hang it somewhere off your STATIC_ROOT so your templates can use
{{STATIC_URL}}/js/tinymce/ and if Apache has been set up with ...

Alias /static/ /var/www/<project>/static/
or
Alias /tiny_mce/ /var/www/<project>/static/js/tiny_mce/

... it should find it. If not, view the page source to see where Apache
is actually looking.

It is different when you are using the Django development server. In my
urls.py I detect when that is the case with ...

tinymcedir = os.path.join(settings.STATIC_ROOT, 'js/tiny_mce/')

if settings.DEBUG:
urlpatterns += patterns('',
(r'^media\/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)
urlpatterns += patterns('',
(r'^static\/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
)

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()
urlpatterns += patterns('',
(r'^tiny_mce/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': tinymcedir}),
)

I'm not sure if this is the "right way" to do it but it works for me.

Mike


> PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
> TINYMCE_JS_URL = os.path.join(PROJECT_ROOT,
> 'templates/static/js/tiny_mce/tiny_mce.js')
> TINYMCE_JS_ROOT = os.path.join(PROJECT_ROOT, 'templates/static/js/tiny_mce')
> * I have a hunch that here is where I'm going wrong. The instructions
> indicate that the tiny_mce js dir should reside in MEDIA, but I was
> under the impression that MEDIA is to be used for user-uploaded content,
> while STATIC is for assets like JS and CSS. That's why I put the
> tiny_mce lib in STATIC instead of MEDIA.
> *
> urls.py*
> urlpatterns = patterns(''
> ...
> url(r'^tinymce/', include('tinymce.urls')),
> )
> * If i visit 'http://127.0.0.1:8000/tinymce/flatpages_link_list/' in the
> browser, 'var tinyMCELinkList = []' is rendered.
>
> Any help would be greatly appreciated. Thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/LzurKyPvBdAJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

Jonathan Baker

unread,
Aug 1, 2012, 11:37:20 PM8/1/12
to django...@googlegroups.com
Thanks Mike. 'tinymce' is included in INSTALLED_APPS because I'm using the app located here: https://github.com/aljosa/django-tinymce/ . I saw a few comments around the web that suggested that this was the route to go to easily integrate TinyMCE.

I've made a few adjustments to no avail. The app is installed, the URLs are configred correctly, and I can navigate to http://127.0.0.1:8000/media/js/tiny_mce/tiny_mce.js and view the JS source. Yet, the WYSIWYG still doesn't display. I'm a bit stumped at this point.


For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Jonathan D. Baker
Developer
http://jonathandbaker.com

Mike Dewhirst

unread,
Aug 2, 2012, 1:09:39 AM8/2/12
to django...@googlegroups.com
On 2/08/2012 1:37pm, Jonathan Baker wrote:
> Thanks Mike. 'tinymce' is included in INSTALLED_APPS because I'm using
> the app located here: https://github.com/aljosa/django-tinymce/ . I saw
> a few comments around the web that suggested that this was the route to
> go to easily integrate TinyMCE.

Sorry - I didn't know it existed. I have actually disabled TinyMCE in my
project for the time being until I can figure out how to selectively
apply it to some textarea widgets (in contrib.admin) and not others.
That's pretty low on my list at the moment. If the app lets that happen
easily I'll give it a try.

Good luck

Mike

>
> I've made a few adjustments to no avail. The app is installed, the URLs
> are configred correctly, and I can navigate to
> http://127.0.0.1:8000/media/js/tiny_mce/tiny_mce.js and view the JS
> source. Yet, the WYSIWYG still doesn't display. I'm a bit stumped at
> this point.
>
> On Wed, Aug 1, 2012 at 7:59 PM, Mike Dewhirst <mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au>> wrote:
>
> On 2/08/2012 11:19am, jondbaker wrote:
>
> I'm trying to install django-tinymce so that I can use utilize
> it within
> the admin when editing flatpages and flatblocks. I've been
> following the
> instructions at
> http://django-tinymce.__readthedocs.org/en/latest/__installation.html
> <http://django-tinymce.readthedocs.org/en/latest/installation.html>,
> but I
> can't seem to get TinyMCE to display. django-tinymce has been
> installed
> via pip, and here are the relevant snippets of code:
>
> *settings.py*
>
> INSTALLED_APPS = (
> ...
> 'tinymce',
> )
>
>
> I have tinyMCE working and no mention of it in settings.py. It isn't
> a Django app.
>
> It needs to be served by your web server eg Apache. The important
> thing is to hang it somewhere off your STATIC_ROOT so your templates
> can use {{STATIC_URL}}/js/tinymce/ and if Apache has been set up
> with ...
>
> Alias /static/ /var/www/<project>/static/
> or
> Alias /tiny_mce/ /var/www/<project>/static/js/__tiny_mce/
>
> ... it should find it. If not, view the page source to see where
> Apache is actually looking.
>
> It is different when you are using the Django development server. In
> my urls.py I detect when that is the case with ...
>
> tinymcedir = os.path.join(settings.STATIC___ROOT, 'js/tiny_mce/')
>
> if settings.DEBUG:
> urlpatterns += patterns('',
> (r'^media\/(?P<path>.*)$',
> 'django.views.static.serve',
> {'document_root': settings.MEDIA_ROOT}),
> )
> urlpatterns += patterns('',
> (r'^static\/(?P<path>.*)$',
> 'django.views.static.serve',
> {'document_root': settings.STATIC_ROOT}),
> )
>
> from django.contrib.staticfiles.__urls import
> staticfiles_urlpatterns
>
> urlpatterns += staticfiles_urlpatterns()
> urlpatterns += patterns('',
> (r'^tiny_mce/(?P<path>.*)$',
> 'django.views.static.serve',
> {'document_root': tinymcedir}),
> )
>
> I'm not sure if this is the "right way" to do it but it works for me.
>
> Mike
>
>
> PROJECT_ROOT = os.path.abspath(os.path.__dirname(__file__))
> TINYMCE_JS_URL = os.path.join(PROJECT_ROOT,
> 'templates/static/js/tiny_mce/__tiny_mce.js')
> TINYMCE_JS_ROOT = os.path.join(PROJECT_ROOT,
> 'templates/static/js/tiny_mce'__)
> * I have a hunch that here is where I'm going wrong. The
> instructions
> indicate that the tiny_mce js dir should reside in MEDIA, but I was
> under the impression that MEDIA is to be used for user-uploaded
> content,
> while STATIC is for assets like JS and CSS. That's why I put the
> tiny_mce lib in STATIC instead of MEDIA.
> *
> urls.py*
>
> urlpatterns = patterns(''
> ...
> url(r'^tinymce/', include('tinymce.urls')),
> )
> * If i visit
> 'http://127.0.0.1:8000/__tinymce/flatpages_link_list/
> <http://127.0.0.1:8000/tinymce/flatpages_link_list/>' in the
> browser, 'var tinyMCELinkList = []' is rendered.
>
> Any help would be greatly appreciated. Thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/__msg/django-users/-/__LzurKyPvBdAJ
> <https://groups.google.com/d/msg/django-users/-/LzurKyPvBdAJ>.
> To post to this group, send email to
> django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <http://groups.google.com/group/django-users?hl=en>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/__group/django-users?hl=en
> <http://groups.google.com/group/django-users?hl=en>.
>
>
>
>
> --
> Jonathan D. Baker
> Developer
> http://jonathandbaker.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.

Aljoša Mohorović

unread,
Aug 2, 2012, 3:11:09 AM8/2/12
to django...@googlegroups.com
On Thu, Aug 2, 2012 at 3:19 AM, jondbaker <jonathand...@gmail.com> wrote:
> TINYMCE_JS_URL = os.path.join(PROJECT_ROOT,
> 'templates/static/js/tiny_mce/tiny_mce.js')
> TINYMCE_JS_ROOT = os.path.join(PROJECT_ROOT, 'templates/static/js/tiny_mce')

You don't need to set TINYMCE_JS_URL/TINYMCE_JS_ROOT because it is set
automatically based on staticfiles settings.
It's available as configuration option if you need to override default setup.
When you "pip install django-tinymce" all required files are copied so
you can skip step 4 as described in docs, you just need to set
STATIC_ROOT/STATIC_URL.

basically, if you have tinymce in INSTALLED_APPS and urlpatterns and
django has staticfiles properly configured it will work as expected.

let me know if you're still having issues w/ setup and feel free to
contact me if you have any questions.

Aljosa
--
https://twitter.com/maljosa
https://github.com/aljosa

Jonathan Baker

unread,
Aug 2, 2012, 5:53:46 PM8/2/12
to django...@googlegroups.com
Thanks for the responses, but I'm still stuck. For now, I'm just trying to add TinyMCE to FlatPages within the Django admin app. When I visit http://127.0.0.1:8000/admin/flatpages/flatpage/add/ the 'content' textarea is rendered without the WYSiWYG, and I don't see any 404s in the terminal looking for JS files. 

Here is the current setup:
local_settings.py http://pastebin.com/m78ZC2Z7

As you'll see, I installed the app, included the URLs, configured static and media for local development and then followed the instructions on https://github.com/jondbaker/django-tinymce/blob/master/docs/usage.rst to use the TinyMCE widget on the 'content' field of the FlatPages form in the admin.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Melvyn Sopacua

unread,
Aug 2, 2012, 10:21:46 PM8/2/12
to django...@googlegroups.com
On 2-8-2012 23:53, Jonathan Baker wrote:
> Thanks for the responses, but I'm still stuck. For now, I'm just trying to
> add TinyMCE to FlatPages within the Django admin app.

Yet another victim of formfield_overrides?
Remember that the Django admin overrides form fields based on their base
class.
--
Melvyn Sopacua

Jonathan Baker

unread,
Aug 2, 2012, 11:58:20 PM8/2/12
to django...@googlegroups.com
"Remember that the Django admin overrides form fields based on their base"
I'm not following what you're saying here. I'm pretty new to Django and just followed the example in the app's documentation. Any tips?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Aljoša Mohorović

unread,
Aug 3, 2012, 5:37:11 AM8/3/12
to django...@googlegroups.com
documentation is not completely updated so steps in previous emails are correct.
i won't be available until next week but check second snippet under:
http://django-tinymce.readthedocs.org/en/latest/usage.html#the-flatpages-link-list-view

and be sure that you have something like:
"""
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, TinyMCEFlatPageAdmin)
"""

Aljosa

Jonathan Baker

unread,
Aug 3, 2012, 12:20:25 PM8/3/12
to django...@googlegroups.com
Success! Thanks for all the help. After integrating your app with the FlatPage app I was able to integrate it with FlatBlock as well.

If you're up for it, I'd love to help update the documentation to save future users (and yourself) some time with the issues I ran in to.

JDB

"""

Aljosa

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Aljoša Mohorović

unread,
Aug 5, 2012, 3:58:24 PM8/5/12
to django...@googlegroups.com
On Fri, Aug 3, 2012 at 6:20 PM, Jonathan Baker
<jonathand...@gmail.com> wrote:
> If you're up for it, I'd love to help update the documentation to save
> future users (and yourself) some time with the issues I ran in to.

sure, just send pull requests for https://github.com/aljosa/django-tinymce
Reply all
Reply to author
Forward
0 new messages