django tinymce不显示丰富的textarea

我的设置:

MEDIA_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
TINYMCE_JS_URL = os.path.join(MEDIA_ROOT, "js/tiny_mce/tiny_mce.js")
TINYMCE_JS_ROOT = os.path.join(MEDIA_ROOT, "js/tiny_mce")
TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,spellchecker,paste,searchreplace",
    'theme': "advanced",
    'cleanup_on_startup': True,
    'custom_undo_redo_levels': 10,
}
TINYMCE_SPELLCHECKER = True
TINYMCE_COMPRESSOR = True

和我的表格:

class AnswerCreationForm(forms.ModelForm):

ans_body = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
class Meta:
    model = Answer 
    fields = ('ans_body',)

在我看来,我这样做是:

<head>
    {{answer_form.media}}
</head>
<form action="{% url "answer-submit" question.id %}" method="get">{% csrf_token %}
{{answer_form.as_p}}
<input type="submit" value="Answer">
</form>

但它不显示富文本,而仅显示普通文本编辑器.

我什至尝试过:

<head>
<script type="text/javascript" src="/static/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinymce.init({
    theme: "advanced",
    width: 300,
    height: 300,
    plugins: [
     "advlist autolink link image lists charmap print preview hr anchor pagebreak      spellchecker",
     "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
     "save table contextmenu directionality emoticons template paste textcolor"
   ],
   content_css: "css/content.css",
   toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons", 
   style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
  }); 
 </script>

 </head>
<form action="{% url "answer-submit" question.id %}" method="get">{% csrf_token %}
{{answer_form.as_p}}
<input type="submit" value="Answer">
</form>

但它也没有显示富文本编辑器?如何显示?我究竟做错了什么 ??

解决方法:

这个答案可以解决这个问题,但希望对您有所帮助.这是我为我的项目找到的解决方案.

我在django-tinymce上也遇到了麻烦,最终我无法解决问题,但是找到了使用直接tinymce而不是django-tinymce应用程序的解决方案.这是我问的问题:django-tinymce modern theme

您所要做的就是在页面上包含此javascript,并用RTE替换textareas.希望这可以满足您的需求.

<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>
tinymce.init({selector:'textarea',
    plugins: [
        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
        "searchreplace wordcount visualblocks visualchars code fullscreen",
        "insertdatetime media nonbreaking save table contextmenu directionality",
        "emoticons template paste textcolor colorpicker textpattern"
    ],
});</script>
上一篇:javascript – TinyMCE:从弹出窗口中检索信息


下一篇:javascript – 如何验证tinyMCE弹出文本框值