django-tinymce plugins not loading django 1.8 - django

I'm trying to implement django-tinymce in my project. I'd love to use some rich text capability when writing my blog posts, so I'm aiming at applying the HTMLField to the body in the admin.
The settings that I am currently using are really simple - this is what I have in settings.py:
TINYMCE_DEFAULT_CONFIG = {
'theme': "advanced",
'plugins': "wordcount,preview,emotions,", //only wordcount seems to have any effect
'height': "400px",
'width': "700px",
}
this is in the models.py:
from tinymce import models as tinymce_models
...
body = tinymce_models.HTMLField()
and I call the .js in the heads like so:
<script type="text/javascript" src="{% static "tiny_mce/tiny_mce.js" %}"></script>
My issue - no matter what I do in the settings, I get the same result:
Here is what I got
I would appreciate any pointers to what I might be doing wrong.
Thanks a bunch!
Deyan

So, after banging my head for a few days, this is what I finally achieved.
settings.py
# tinymce
TINYMCE_DEFAULT_CONFIG = {
'theme': "advanced",
'plugins': "wordcount,preview,emotions,preview,spellchecker,",
'height': "400px",
'width': "700px",
'theme_advanced_buttons3' : "fontselect,fontsizeselect,emotions,preview,",
}
models.py
from tinymce.models import HTMLField
...
body = HTMLField()
result:
As you can see, smilies are smiling beautifully, I've got control over font family and size, it's looking really ugly, but it works and this is the price you pay for hacking stuff I suppose. But it works!
I found this list of plugins and buttons really helpful - what I wasn't getting before was that the plugins you only load into your django app, but in order to use them, you need to call their buttons. Really straightforward once you get it, but there you go.
Thanks!

Related

Use differents configs in CKEDITOR with Django

In my Django back end, I have a full toolbar.
However, I want to propose Ckeditor to my users with a minimum of functionnalities.
The problem is, I don't know how to this.
I tried to override my config :
<script type="text/javascript">
CKEDITOR.replace( 'default',
{
toolbar : 'Basic',
});
</script>
But nothing happened, even after removing my browser cache.
This is my Django settings :
CKEDITOR_BASEPATH = "/static/ckeditor/ckeditor/"
CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'full',
'height': 500,
'width': 1500,
},
}
Maybe it is not working because in your Django code the settings "CKEDITOR_CONFIGS" for toolbar defined as full.
Also, you can configure toolbar through online builder - https://ckeditor.com/docs/ckeditor4/latest/guide/dev_plugins.html.

django-ckeditor formatting not in html post

I have an issue similar to this previous question : Django-ckeditor not displaying correctly in html
except that my settings seem to be ok but still not displaying in the html page. What am I missing?
settings.py
INSTALLED_APPS = [
'ckeditor',
'ckeditor_uploader',
]
CKEDITOR_CONFIGS = {
'awesome_ckeditor': {
'toolbar': 'full',
},
}
CKEDITOR_IMAGE_BACKEND = "pillow"
and in the html page rendering the edited post I have:
post_detail.html
<div class="post-content">{{post.text|safe|linebreaksbr}}</div>
Everything works fine on the admin side:
yet it is not displayed on the page:
It seems that the html was rendered properly and only missing css formatting to add for the html tags. I am leaving this post in case it could be useful for someone to check for such issue.

Installing TinyMCE on Django (And using it on forms)

Hi Im trying to install TinyMCE on a Django project and Im totally lost about static files, MEDIA, and the world itself.
I want to use TinyMCE in one of the fields of a form:
class MovieForm(forms.ModelForm):
class Meta:
model = Movie
fields = ['title', 'language', 'description']
widgets = {
'languages': forms.SelectMultiple(),
'description': TinyMCE({'cols':80, 'rows':30}),
}
I installed django-tinymce
pip install django-tinymce
Then I added it to the installed apps
INSTALLED_APPS = (
...
'tinymce',
...
)
And then added the urls in my project urls.py
urlpatterns = patterns('',
...
(r'^tinymce/', include('tinymce.urls')),
...
)
Great. So what do I do next?
I read the Configuration part on http://django-tinymce.readthedocs.io/en/latest/installation.html#configuration but I dont get it.
Should I add TINYMCE_JS_URL = os.path.join(MEDIA_URL, "path/to/tiny_mce/tiny_mce.js") to my project settings.py? Where do I put tiny_mce.js? Should I configure MEDIA_URL somewhere?
Would be awesome if someone can point me in the right direction.
Thanks! :)
I figured this, so I'm posting an answer in case anyone else comes across this.
I read more in details the documentation on Static files (https://docs.djangoproject.com/en/1.10/howto/static-files/), and read the related section of the great book Tango with Django (http://www.tangowithdjango.com/).
That helped me to understand the MEDIA and STATIC setup I needed to get right in order to get working TinyMCE with Django.
tiny_mce.js went to the static files folder (specifically to static/tiny_mce/).
The settings.py of Tinymce check if static is confidured, and points there to get the needed files. Tadaa! It works!
Hopefully it will help someone!

django tinymce does not show toolbar

i have install django-tinymce and set js url and js root correctly
but as a result it show only a simple text area and doesnt show toolbar and other tinymce features:
from django.db import models
from tinymce import models as tinymce_models
class MyModel(models.Model):
content= HTMLField()
i use this:
self.fields['content'].widget=TinyMCE(attrs={'cols': 80, 'rows': 30})
but this not work too! and it show only a simple text area with 80 cols and 30 rows size.
please help me! what should i do?
Make sure you have added tinymce urls to your urls.py and loaded media resources in your templates like:
<head>
...
{{ form.media }}
</head>
There is my django-tinymce config, add them to your settings.py:
TINYMCE_DEFAULT_CONFIG = {
'theme': 'advanced',
'relative_urls': False,
'plugins': 'media',
'theme_advanced_buttons1': 'bold,italic,underline,bullist,numlist,|,media,link,unlink,image',
'theme_advanced_resizing': True,
'theme_advanced_path': False,
}
You can get more details via reading the docs.

django-cms, django flatpages, tiny mce not displaying

I've implemented both django-cms and flatpages, but can not get tiny_mce to display in either.
urls.py
(r'^tinymce/', include('tinymce.urls')),
from django.conf import settings
if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)
settings.py
TINYMCE_JS_URL = 'http://127.0.0.1:8000/site_media/js/tiny_mce/tiny_mce.js'
TINYMCE_JS_ROOT = 'http://127.0.0.1:8000/site_media/js/tinymce/'
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,spellchecker,paste,searchreplace",
'theme': "advanced",
'cleanup_on_startup': True,
'custom_undo_redo_levels': 10,
}
TINYMCE_SPELLCHECKER = False
TINYMCE_COMPRESSOR = False
TINYMCE_FILEBROWSER = True
CMS_USE_TINYMCE = True
admin.py
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin
#Flatpages
class FlatPageAdmin(FlatPageAdmin):
class Media:
js = ('http://127.0.0.1:8000/js/tiny_mce/tiny_mce.js',
'http://127.0.0.1:8000/js/tiny_mce/textareas.js',)
# We have to unregister it, and then reregister
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
#django-cms
from myprograms.cms.models import Page
class PageOptions(admin.ModelAdmin):
class Media:
js = ('http://127.0.0.1:8000/site_media/js/tiny_mce/tiny_mce.js',
'http://127.0.0.1:8000/site_media/js/tiny_mce/textareas.js')
#admin.site.register(Page, PageOptions)
In the base.html file
<script type="text/javascript" src="{{ MEDIA_URL }}js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="{% url tinymce-js "NAME" %}"></script>
There are so many different options when accessing the various user groups, docs, etc. I'm not sure what is the correct syntax. The CMS doesn't do me much good without some kind of text editor.
Thx
first of all please check this line with slash like:
<script type="text/javascript" src="{{ MEDIA_URL }}/js/tiny_mce/tiny_mce.js"></script>
also please check site_id in error logs. had similar issue with site_id because I created new site with different id.
Best,
Mykola Lys.
If you need some more features then the simple flatpages just checkout django-blocks (http://code.google.com/p/django-blocks/). Has multi-language Menu, Flatpages and even has a simple Shopping Cart!!
Have you read the TinyMCE page on the Django wiki? Also - although it looks like it might not apply to you - browsers block calls from scripts across differing servers/domains...