在 django 中调整 TinyMCE 的大小

发布于 2025-01-20 17:16:42 字数 463 浏览 4 评论 0原文

我正在尝试编写一个小部件来调整我的django tinymce大小,但似乎没有用...

有人知道此代码段问题是什么?

from django import forms 
from .models import blog, comment, reply, like, subscription
from tinymce.widgets import TinyMCE

class blogform(forms.ModelForm):
    class Meta:
        model = blog
        fields  = ['content', 'title', 'blog_pic']
        widgets = {'content': (TinyMCE(attrs={'style':'height:100vh; width:60%'}))}

I am trying to write a widget to resize my django tinymce but it doesn't seem to work...

Does anyone know what the problem is with this code snippet?

from django import forms 
from .models import blog, comment, reply, like, subscription
from tinymce.widgets import TinyMCE

class blogform(forms.ModelForm):
    class Meta:
        model = blog
        fields  = ['content', 'title', 'blog_pic']
        widgets = {'content': (TinyMCE(attrs={'style':'height:100vh; width:60%'}))}

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

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

发布评论

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

评论(1

柠檬 2025-01-27 17:16:42

我弄清楚了问题是什么;我的静态文件夹中有一个app.js文件,该文件具有为Tinymce编辑器设计的配置。我要做的就是更改宽度或高度以满足我的需求...这是代码

    tinymce.init({
        selector: "textarea",      
        height: "700",
        width: "60%",
        plugins: "insertdatetime media image preview",
        toolbar: "undo redo |  bold italic | alignleft alignright                           aligncenter alignjustify | image media | preview",
        image_title: true,
image_caption: true,
automatic_uploads: true,
image_advtab: true,
file_picker_types: "image media",

file_picker_callback: function (cb, value, meta) {
  var input = document.createElement("input");
  input.setAttribute("type", "file");
  if (meta.filetype == "image") {
      input.setAttribute("accept", "image/*");}
  if (meta.filetype == "media") {
  input.setAttribute("accept", "video/*");}

  input.onchange = function () {     
      var file = this.files[0];
      var reader = new FileReader();
      reader.onload = function () {
          var id = "blobid" + (new Date()).getTime();
          var blobCache =  tinymce.activeEditor.editorUpload.blobCache;
          var base64 = reader.result.split(",")[1];
          var blobInfo = blobCache.create(id, file, base64);
          blobCache.add(blobInfo);
         cb(blobInfo.blobUri(), { title: file.name });
       };
       reader.readAsDataURL(file);
   };
   input.click();
},
content_style: "body { font-family:Helvetica,Arial,sans-serif; font-size:14px }"});

I figured out what the problem was;I had an app.js file in my static folder that had a configuration to style the tinymce editor; all i had to do was change the width or height to fit my needs...this is the code

    tinymce.init({
        selector: "textarea",      
        height: "700",
        width: "60%",
        plugins: "insertdatetime media image preview",
        toolbar: "undo redo |  bold italic | alignleft alignright                           aligncenter alignjustify | image media | preview",
        image_title: true,
image_caption: true,
automatic_uploads: true,
image_advtab: true,
file_picker_types: "image media",

file_picker_callback: function (cb, value, meta) {
  var input = document.createElement("input");
  input.setAttribute("type", "file");
  if (meta.filetype == "image") {
      input.setAttribute("accept", "image/*");}
  if (meta.filetype == "media") {
  input.setAttribute("accept", "video/*");}

  input.onchange = function () {     
      var file = this.files[0];
      var reader = new FileReader();
      reader.onload = function () {
          var id = "blobid" + (new Date()).getTime();
          var blobCache =  tinymce.activeEditor.editorUpload.blobCache;
          var base64 = reader.result.split(",")[1];
          var blobInfo = blobCache.create(id, file, base64);
          blobCache.add(blobInfo);
         cb(blobInfo.blobUri(), { title: file.name });
       };
       reader.readAsDataURL(file);
   };
   input.click();
},
content_style: "body { font-family:Helvetica,Arial,sans-serif; font-size:14px }"});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文