Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django tinymce未显示丰富的文本区域_Python_Django_Forms_Tinymce - Fatal编程技术网

Python django tinymce未显示丰富的文本区域

Python django tinymce未显示丰富的文本区域,python,django,forms,tinymce,Python,Django,Forms,Tinymce,我的设置: 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_DEFAUL

我的设置:

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>

{{answer_form.media}
{%csrf_令牌%}
{{answer_form.as_p}}
但它不显示富文本,只显示普通文本编辑器

我甚至试过:

<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>

tinymce.init({
主题:“高级”,
宽度:300,
身高:300,
插件:[
“advlist autolink图像列表charmap打印预览hr锚定页面中断拼写检查器”,
“searchreplace wordcount visualblocks visualchars代码全屏插入日期时间媒体非中断”,
“保存表格上下文菜单方向性表情模板粘贴文本颜色”
],
content\u css:“css/content.css”,
工具栏:“插入文件撤消重做|样式选择|粗体斜体|对齐左对齐居中对齐右对齐对齐对齐|粗体numlist outdent缩进| l墨水图像|打印预览媒体全页|前景色背景色表情”,
样式和格式:[
{标题:“粗体文本”,内联:“b'},
{标题:'Red text',内联:'span',样式:{color:'#ff0000'}},
{title:'Red header',block:'h1',style:{color:'#ff0000'}},
{title:'example1',inline:'span',classes:'example1'},
{title:'example2',inline:'span',classes:'example2'},
{title:'表格样式'},
{title:'Table row 1',选择器:'tr',类:'tablerow 1'}
]
}); 
{%csrf_令牌%}
{{answer_form.as_p}}

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

这个答案有点回避了这个问题,但希望它能帮助你。这是我为我的项目找到的解决方案

我也有django tinymce的问题,我最终无法解决这个问题,但我用straight tinymce而不是django tinymce应用程序找到了解决方案。以下是我提出的问题:

您所要做的就是在页面上包含此javascript,并用RTE替换文本区域。希望这能满足你的需要

<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>

tinymce.init({选择器:'textarea',
插件:[
“advlist autolink列出链接图像charmap打印预览hr锚定页面中断”,
“searchreplace wordcount visualblocks visualchars代码全屏显示”,
“insertdatetime媒体非中断保存表上下文菜单方向性”,
“表情模板粘贴文本颜色选择器文本模式”
],
});

我知道你解决了你的问题,但当我在寻找答案来解决我在前端没有显示所需内容的问题时,我回复你:

您只需要在前端进行筛选,因此在模板文件中添加如下内容:

{{ your_view_context.your_model_field | safe }}

检查您是否完成了所有步骤。我已正确完成了每个步骤,并进行了测试。。它在测试中显示富文本。如何在模型形式中使用它?我在django tinymce上也遇到了问题。我使用了@awwestersolution..并且工作得很有魅力