TinyMCE:格式化我的tinymce编辑器会杀死django功能

发布于 2024-12-28 05:17:21 字数 1549 浏览 3 评论 0原文

我已将tinymce 表单嵌入到django 应用程序中。我遵循了一些在线教程,它在基本默认设置下运行良好。唯一的问题是tinymce 表单看起来不像我想要的那样。因此,我添加了一些 javascript 来添加更多按钮,将它们移动到 tinymce 区域的顶部。

当我添加 javascript 时,表单不起作用。也就是说,当我单击“保存”按钮时,我的新编辑不会传输回服务器。

以下呈现tinymce 形式:

 <form action="/edit_document/{{ current_doc.id }}/" method="post">{% csrf_token %}
   Name: {{ form.name }} <p>
   {{ form.content }}
   <input type="submit" value="SAVE" />
 </form>

上面的代码一直有效,直到我添加以下javascript 来格式化我的tinymce 编辑器。

<script type="text/javascript"> tinyMCE.init({  
    mode: "textareas",  
    theme: "advanced",  
    plugins: "advhr,table,emotions,media,insertdatetime,directionality", 
    theme_advanced_toolbar_align: "left",  
    theme_advanced_toolbar_location: "top", 
    theme_advanced_buttons1:"bold,italic,underline,strikethrough,sub,sup,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,formatselect,fontselect,fontsizeselect", 
    theme_advanced_buttons2:"bullist,numlist,outdent,indent,ltr,rtl,separator,link,unlink,anchor,image,separator,table,insertdate,inserttime,advhr,emotions,media,charmap,separator,undo,redo", 
    theme_advanced_buttons3: "",  
    content_css: "images/style.css",  
    height: "350px", 
    width: "653px"  
    });  
</script> 

现在发生的情况是 form.content 没有传递回 django 视图,而是得到原始内容减去任何新的编辑。

这里可能发生什么?我该如何修复它?


经过多次尝试和错误,这是解决方案。不要将脚本放在网页顶部来格式化tinymce元素。相反,构建一个特殊的小部件来格式化小部件。即使脚本是相同的,它也会对 django 解释该字段的方式产生影响。

I have embedded a tinymce form into a django app. I followed some online tutorials and it worked fine in its basic default setting. The only problem was that the tinymce form didn't look the way I wanted. So I added some javascript to add more buttons to move them to the top of the tinymce area.

When I add in the javascript the form doesn't work. That is my new edits are not transmitted back to the server when I click the SAVE button.

The following renders the tinymce form:

 <form action="/edit_document/{{ current_doc.id }}/" method="post">{% csrf_token %}
   Name: {{ form.name }} <p>
   {{ form.content }}
   <input type="submit" value="SAVE" />
 </form>

The above code works until I add the following javascript to format my tinymce editor.

<script type="text/javascript"> tinyMCE.init({  
    mode: "textareas",  
    theme: "advanced",  
    plugins: "advhr,table,emotions,media,insertdatetime,directionality", 
    theme_advanced_toolbar_align: "left",  
    theme_advanced_toolbar_location: "top", 
    theme_advanced_buttons1:"bold,italic,underline,strikethrough,sub,sup,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,formatselect,fontselect,fontsizeselect", 
    theme_advanced_buttons2:"bullist,numlist,outdent,indent,ltr,rtl,separator,link,unlink,anchor,image,separator,table,insertdate,inserttime,advhr,emotions,media,charmap,separator,undo,redo", 
    theme_advanced_buttons3: "",  
    content_css: "images/style.css",  
    height: "350px", 
    width: "653px"  
    });  
</script> 

What happens now is that the form.content is not passed back to the django view, rather I get the original content minus any new edits.

What could be happening here? How can I fix it?


After much trial and error, here is the solution. Do not put the script at the top of the web page to format tinymce elements. Instead build a special widget that formats the widget. Even thought the script is the same it makes a difference to how django interprets the field.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素年丶 2025-01-04 05:17:21

经过多次尝试和错误,这是解决方案。不要将脚本放在网页顶部来格式化tinymce元素。相反,构建一个特殊的小部件来格式化小部件。即使脚本是相同的,它也会对 django 解释该字段的方式产生影响。

After much trial and error, here is the solution. Do not put the script at the top of the web page to format tinymce elements. Instead build a special widget that formats the widget. Even thought the script is the same it makes a difference to how django interprets the field.

浊酒尽余欢 2025-01-04 05:17:21

尝试这个而不是使用 {{ form.content}}

{{ form.content|safe }}

希望它有帮助。

Try this instead of using {{ form.content}}:

{{ form.content|safe }}

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文