如何在Django Summernote中显示用于编程片段的代码块?

问题描述

我正在website上使用Django Summernote。这就是编辑器的外观。

enter image description here

您可以在下面找到我的Summernote编辑器的Django设置。

SUMMERNOTE_CONfig = {
    # Or,you can set it as False to use SummernoteInplaceWidget by default - no iframe mode
    # In this case,you have to load Bootstrap/jQuery stuff by manually.
    # Use this when you're already using Bootstraip/jQuery based themes.
    'iframe': False,# You can put custom Summernote settings
    'summernote': {
        # As an example,using Summernote Air-mode
        'airMode': False,# Change editor size
        'width': '100%','height': '480','toolbar': [
            ['style',['style']],['font',['bold','underline','clear']],['fontname',['fontname']],['color',['color']],['para',['ul','ol','paragraph']],['table',['table']],['insert',['link','picture','video']],['view',['fullscreen','codeview','help']],],'codemirror': {
            'mode': 'htmlmixed','lineNumbers': 'true',# You have to include theme file in 'css' or 'css_for_inplace' before using it.
            'theme': 'monokai',},}
}

但是遗憾的是,它没有代码的选项来显示编程片段。我在这里做什么错了?

解决方法

Django Summernote已经具有内置的代码格式

django summernote

尝试在django项目中重新安装django summernote,并确保正确获得其GitHub Repository中所述的所有安装说明

,

我遇到了同样的问题,您必须切换(降级)才能在settings.py文件中引导3:

    SUMMERNOTE_THEME = 'bs3'

我不知道为什么bs4没有内置样式。如果您坚持使用bs4,则必须将外部插件与django summernote一起使用,并在settings.py中再次编辑summernote配置:

SUMMERNOTE_CONFIG = { 
    
    'summernote' : {
        'width': '100%','height': '720','codemirror': {
        'mode': 'htmlmixed','lineNumbers': 'true',}
}
}

此示例用于将代码镜像外部插件与summernote一起使用(并更改字段的大小)