1

I am using Django 1.5.1, and as we know since Django 1.3 the world of Media and statis files have been separated for good reasons.

To my surprise django-tinymce's documentation is referring to how TINYMCE_JS_URL is pointing by default to the media url.

TINYMCE_JS_URL (default: settings.MEDIA_URL + 'js/tiny_mce/tiny_mce.js')

That doesn't make much sense. As in Django 1.3+ we have the static_url for self hosted js and css files. But trying to change that is confusing and doesn't work.

This is how I usually setup my static files settings:

STATIC_ROOT = '/home/kave/project-env/site/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = ('/home/kave/project-env/site/static_files/',)

In the static_files directory I have extracted the TINYMCE zipfile: e.g. the path is like this:

/home/kave/project-env/site/static_files/tinymce/js/tinymce/tinymce.min.js

Then I have set the settings like this:

TINYMCE_JS_URL = STATIC_URL + 'tinymce/js/tinymce/tinymce.min.js'
TINYMCE_JS_ROOT = STATIC_ROOT + 'tinymce/js/tinymce'

However when the app runs, I see a plain textfield instead of TINYMCE.

WHat could I have overlooked please?

4

2 回答 2

4

我终于弄明白了,希望它可以帮助别人。

您需要指向通过 pip 自动安装的内置 tiny_mce。无需下载任何东西。

<script type="text/javascript" src="{{ STATIC_URL }}tiny_mce/tiny_mce.js"></script>

对于管理屏幕,确保你有这个:

class TinyMCEAdmin(admin.ModelAdmin):
    class Media:
        js = ('/static/tiny_mce/tiny_mce.js', )

admin.site.register(MyModel, TinyMCEAdmin)

并且不要忘记 settings.py 中的配置

TINYMCE_DEFAULT_CONFIG = {
    # General options
    'mode' : "textareas",
    'theme' : "advanced",
    'plugins' : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

    # Theme options
    'theme_advanced_buttons1' : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,", #fullscreen,code",
    'theme_advanced_buttons2' : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,|,forecolor,backcolor",
    #'theme_advanced_buttons3' : "tablecontrols,|,hr,sub,sup,|,charmap",

    'theme_advanced_toolbar_location' : "top",
    'theme_advanced_toolbar_align' : "left",
    'theme_advanced_statusbar_location' : "bottom",
    'theme_advanced_resizing' : 'true',

    #Example content CSS (should be your site CSS)
    #content_css : "/css/style.css",

    'template_external_list_url' : "lists/template_list.js",
    'external_link_list_url' : "lists/link_list.js",
    'external_image_list_url' : "lists/image_list.js",
    'media_external_list_url' : "lists/media_list.js",

    # Style formats
    'style_formats' : [
        {'title' : 'Bold text', 'inline' : 'strong'},
        {'title' : 'Red text', 'inline' : 'span', 'styles' : {'color' : '#ff0000'}},
        {'title' : 'Help', 'inline' : 'strong', 'classes' : 'help'},
        {'title' : 'Table styles'},
        {'title' : 'Table row 1', 'selector' : 'tr', 'classes' : 'tablerow'}
    ],

    'width': '700',
    'height': '400'
}

除此之外,请确保将模型内的 HTMLField 用于任何模型文本字段。在 forms.py 中,如果您不使用 modelform,您还需要定义新的小部件。

于 2013-04-21T16:59:43.867 回答
0

使用 django-tinymce

我们必须配置以下

设置.py

INSTALLED_APPS = [
  # .......
  'tinymce',
  # .......
]

TINYMCE_JS_URL = '%sjavascript/tiny_mce/' % (STATIC_URL)

网址.py

urlpatterns = [
  # .....
  url(r'^tinymce/', include('tinymce.urls')),
  # .....
]
于 2018-04-19T06:17:55.577 回答