Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to enable a plugin within django-tinymce?

I have started using tinymce in my django project. I need to enable some plugins which come bundled with django-tinymce (for example, template). So, within my settings.py, I have added the following configuration:

TINYMCE_DEFAULT_CONFIG = {
    'theme': 'advanced', 'relative_urls': False,
    'plugins': 'template',
    'toolbar': 'template'
}
MAX_UPLOAD_SIZE = 512000

Thinking that they might enable the template plugin, but it seems not. How do I enable a plugin within django-tinymce? I have not found this anywhere.

Thanks for your suggestions!

UPDATE:

I think I had misunderstood how the configuration is done. I have created a config.js with some configuration:

tinyMCE.init({
    theme: 'advanced',
    plugins: 'template',
    height: '350px',
    width: '1000px'
});

Then, I have linked it from MyModelAdmin.Media. (I'm loading the editor from django-admin.)

class MyModelAdmin(ModelAdmin):
    class Media:
        from django.conf import settings
        js = (
            settings.STATIC_URL + 'tiny_mce/config.js',
        )

config.js seems loading correctly, but I can't see any difference.

like image 879
sogeking Avatar asked Oct 21 '22 11:10

sogeking


1 Answers

You can pass mce_attrs param to TinyMCE widget for tinymce configuration.

from django import forms
from django.contrib.flatpages.models import FlatPage
from tinymce.widgets import TinyMCE


class FlatPageForm(forms.ModelForm):

    content = forms.CharField(widget=TinyMCE(mce_attrs={
        'theme': 'advanced',
        'plugins': 'template',
        'height': '350px',
        'width': '1000px'
    }))

    class Meta:
        model = FlatPage
like image 196
vanadium23 Avatar answered Oct 23 '22 03:10

vanadium23