【问题标题】:How do I change default font of Summernote in Django?如何在 Django 中更改 Summernote 的默认字体?
【发布时间】:2020-08-22 20:49:48
【问题描述】:

所以我正在使用 django-summernote(我正在使用 Django ver 3.x),并尝试更改编辑器中的默认字体。这是我的代码。

(部分)forms.py:

from .models import MyModel

class MyInputForm(forms.ModelForm):
    contents = SummernoteTextFormField()

        class Meta:
        model=MyModel
        fields=['contents']
        widgets = {
        'contents': SummernoteInplaceWidget()
        }

(部分)我的模板:

<form method="post" class="form-group">
  {% csrf_token %}
  <div class="row">
    <div class="col col-8">
      {{form.contents|as_crispy_field}}
    </div>
  </div>
</form>

如果您需要查看,(部分)我的 settings.py

SUMMERNOTE_CONFIG = {
    'iframe': True,
    'lang' : 'ko-KR',
    'summernote': {
        'width': '100%',
        'height': '400px',
        'toolbar': [
            ['style', ['style',]],
            ['font', ['fontname', 'fontsize', 'bold', 'italic', 'strikethrough', 'clear',]],
            ['color', ['forecolor', 'backcolor', ]],
            ['para', ['ul', 'ol', 'height']],
            ['insert', ['link']],
            ['misc', ['picture', 'fullscreen', 'codeview', 'print', 'help', ]],
        ],
    },
    'js': (
        '/static/summernote-ext-print.js',
    ),
    'js_for_inplace': (
        '/static/summernote-ext-print.js',
    ),
    'css': (
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/5.40.0/theme/base16-dark.min.css',
    ),
    'css_for_inplace': (
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/5.40.0/theme/base16-dark.min.css',
    ),
    'codemirror': {
        'theme': 'base16-dark',
        'mode': 'htmlmixed',
        'lineNumbers': 'true',
    },
    'lazy': False,
}

SUMMERNOTE_THEME = 'bs4'
X_FRAME_OPTIONS = 'SAMEORIGIN'

我不知道如何或在哪里编写更改默认字体的代码。
我将衷心感谢您的帮助。谢谢。 :)

【问题讨论】:

    标签: django summernote


    【解决方案1】:

    与 django-summernote 无关。您需要检查并初始化您的 css 样式或 html 文件中的默认字体系列。此外,您可能需要检查下拉菜单中显示的内容,检查fontNames option

    SUMMERNOTE_CONFIG = {
        'summernote': {
            'fontNames': [...],
        },
    }
    

    【讨论】:

      【解决方案2】:

      可以通过以下方式向列表中添加更多字体:

      SUMMERNOTE_CONFIG = {
          'summernote': {
              'fontNames': ['Spectral', 'Quicksand'],
              'fontNamesIgnoreCheck': ['Spectral', 'Quicksand'],
          },
      }
      

      Summernote 测试 fontNames 中的字体,然后再将它们添加到 落下。这是使用网络字体时的问题。这并不容易 选择一个检查网络字体可用性的好时机。你可以 定义要忽略的 Web 字体列表 fontNamesIgnoreCheck.

      参考:https://summernote.org/deep-dive/#custom-fontnames

      【讨论】:

        【解决方案3】:

        你不应该担心这个。在编辑器中复制粘贴任意格式的文本,summernote会接受并调整。

        【讨论】:

          猜你喜欢
          • 2021-03-17
          • 2019-04-07
          • 1970-01-01
          • 1970-01-01
          • 2017-12-10
          • 1970-01-01
          • 2011-06-23
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多