Python 为什么';当使用ckeditor和Django时,MathJax预览不会显示吗?

Python 为什么';当使用ckeditor和Django时,MathJax预览不会显示吗?,python,django,ckeditor,mathjax,django-ckeditor,Python,Django,Ckeditor,Mathjax,Django Ckeditor,我目前正在尝试使用Django创建一个简单的网站,其中包含用于表单字段的ckeditor。我还想将一些数学知识集成到我的表单中,因此我下载了ckeditor插件 我随后实现了插件,但MathJax不起作用 这是我添加到settings.py文件中的内容 CKEDITOR_CONFIGS = { 'default': { 'toolbar':'full', 'height': '400px', 'width': '100%',

我目前正在尝试使用Django创建一个简单的网站,其中包含用于表单字段的ckeditor。我还想将一些数学知识集成到我的表单中,因此我下载了ckeditor插件

我随后实现了插件,但MathJax不起作用

这是我添加到settings.py文件中的内容

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar':'full',
        'height': '400px',
        'width': '100%',
        'extraPlugins': ','.join(
            [
                'mathjax', 
                'widget', 
                'lineutils', 
                'dialog', 
                'clipboard',
                
            ]),
    },

}
我将下载的MathJax文件夹复制到项目的静态目录中。然后,我在models.py文件中引用了以下内容:

from django.db import models
from django.contrib.auth.models import User
from ckeditor.fields import RichTextField

class Entry(models.Model):
    entry_title = models.CharField(max_length=100)
    #entry_text = models.TextField()
    entry_text = RichTextField(blank = True, null = True,config_name = 'default', external_plugin_resources=[(
        'mathjax',
        '/static/entries/vendor/ckeditor_plugins/mathjax/',
        'plugin.js',
    )])
    entry_date = models.DateTimeField(auto_now_add = True)
    entry_author = models.ForeignKey(User, on_delete = models.CASCADE)

    class Meta:
        verbose_name_plural = "entries"

    def __str__(self):
        return f'{self.entry_title}'
当我使用表格时,我可以看到数学公式符号:

当我点击它时,ckeditor让我可以自由地在Tex字段中键入任何我想要的内容:

然而,它并没有给我一个预览它在渲染后的样子。 这与数学公式网站相矛盾,该网站给出了一个数学公式的示例:

此外,当我用虚拟Tex输入单击ok时,它在ckeditor框中不会显示任何内容。在我的终端
未找到:/create_entry/undefined
“GET/create_entry/undefined HTTP/1.1”404 2644
中会出现一条消息“create_entry”是我在创建表单时使用的URL模式

当我提交一个包含一些数学信息的表单时,我无法在ckeditor字段中实际看到数学信息-只有一个蓝色光标:

但是,在提交后查看此帖子时,数学呈现:

我不确定这是否是因为我在base.html文件中添加了以下javascript:

    <script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
  </script>

我在网站上找到了它。

根据需要指定mathjax路径的文档,在CKEDITOR配置中

底部有示例的一般文档:


路径配置变量需要:

我将此代码复制到我的settings.py文件中,它可以工作:

# CKEditor UI and plugins configuration
CKEDITOR_CONFIGS = {
    'default': {
        # Toolbar configuration
        # name - Toolbar name
        # items - The buttons enabled in the toolbar
        'toolbar_DefaultToolbarConfig': [
            {
                'name': 'basicstyles',
                'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript',
                          'Superscript', ],
            },
            {
                'name': 'clipboard',
                'items': ['Undo', 'Redo', ],
            },
            {
                'name': 'paragraph',
                'items': ['NumberedList', 'BulletedList', 'Outdent', 'Indent',
                          'HorizontalRule', 'JustifyLeft', 'JustifyCenter',
                          'JustifyRight', 'JustifyBlock', ],
            },
            {
                'name': 'format',
                'items': ['Format', ],
            },
            {
                'name': 'extra',
                'items': ['Link', 'Unlink', 'Blockquote', 'Image', 'Table',
                          'CodeSnippet', 'Mathjax', 'Embed', ],
            },
            {
                'name': 'source',
                'items': ['Maximize', 'Source', ],
            },
        ],

        # This hides the default title provided by CKEditor
        'title': False,

        # Use this toolbar
        'toolbar': 'DefaultToolbarConfig',

        # Which tags to allow in format tab
        'format_tags': 'p;h1;h2',

        # Remove these dialog tabs (semicolon separated dialog:tab)
        'removeDialogTabs': ';'.join([
            'image:advanced',
            'image:Link',
            'link:upload',
            'table:advanced',
            'tableProperties:advanced',
        ]),
        'linkShowTargetTab': False,
        'linkShowAdvancedTab': False,

        # CKEditor height and width settings
        'height': '250px',
        'width': 'auto',
        'forcePasteAsPlainText ': True,

        # Class used inside span to render mathematical formulae using latex
        'mathJaxClass': 'mathjax-latex',

        # Mathjax library link to be used to render mathematical formulae
        'mathJaxLib': 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_SVG',

        # Tab = 4 spaces inside the editor
        'tabSpaces': 4,

        # Extra plugins to be used in the editor
        'extraPlugins': ','.join([
            # 'devtools',  # Shows a tooltip in dialog boxes for developers
            'mathjax',  # Used to render mathematical formulae
            'codesnippet',  # Used to add code snippets
            'image2',  # Loads new and better image dialog
            'embed',  # Used for embedding media (YouTube/Slideshare etc)
            'tableresize',  # Used to allow resizing of columns in tables
        ]),
    }
}
CKEDITOR_CONFIGS = {
    'default': {
        # Toolbar configuration
        # name - Toolbar name
        # items - The buttons enabled in the toolbar
        'toolbar_DefaultToolbarConfig': [
            {
                'name': 'basicstyles',
                'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript',
                          'Superscript', ],
            },
            {
                'name': 'clipboard',
                'items': ['Undo', 'Redo', ],
            },
            {
                'name': 'paragraph',
                'items': ['NumberedList', 'BulletedList', 'Outdent', 'Indent',
                          'HorizontalRule', 'JustifyLeft', 'JustifyCenter',
                          'JustifyRight', 'JustifyBlock', ],
            },
            {
                'name': 'format',
                'items': ['Format', ],
            },
            {
                'name': 'extra',
                'items': ['Link', 'Unlink', 'Blockquote', 'Image', 'Table',
                          'CodeSnippet', 'Mathjax', 'Embed', ],
            },
            {
                'name': 'source',
                'items': ['Maximize', 'Source', ],
            },
        ],

        # This hides the default title provided by CKEditor
        'title': False,

        # Use this toolbar
        'toolbar': 'DefaultToolbarConfig',

        # Which tags to allow in format tab
        'format_tags': 'p;h1;h2',

        # Remove these dialog tabs (semicolon separated dialog:tab)
        'removeDialogTabs': ';'.join([
            'image:advanced',
            'image:Link',
            'link:upload',
            'table:advanced',
            'tableProperties:advanced',
        ]),
        'linkShowTargetTab': False,
        'linkShowAdvancedTab': False,

        # CKEditor height and width settings
        'height': '250px',
        'width': 'auto',
        'forcePasteAsPlainText ': True,

        # Class used inside span to render mathematical formulae using latex
        'mathJaxClass': 'mathjax-latex',

        # Mathjax library link to be used to render mathematical formulae
        'mathJaxLib': 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_SVG',

        # Tab = 4 spaces inside the editor
        'tabSpaces': 4,

        # Extra plugins to be used in the editor
        'extraPlugins': ','.join([
            # 'devtools',  # Shows a tooltip in dialog boxes for developers
            'mathjax',  # Used to render mathematical formulae
            'codesnippet',  # Used to add code snippets
            'image2',  # Loads new and better image dialog
            'embed',  # Used for embedding media (YouTube/Slideshare etc)
            'tableresize',  # Used to allow resizing of columns in tables
        ]),
    }
}

似乎我没有在预览中添加渲染乳胶的线条。

感谢您的快速回复。这在config.js文件中吗?老实说,我没有用CKEDITOR做任何事情,但是看看上面的代码,我会先在extraPlugins后面的setting.py中的CKEDITOR_CONFIGS中尝试它。
CKEDITOR_CONFIGS={'default':{'toolbar':'full','height':'400px','width':'100%,'extraPlugins':'(['mathjax','widget','lineutils','dialog','clipboard',]),'external_plugin_resources':[('mathjax','/static/entries/vendor/ckeditor_plugins/mathjax/','plugin.js',)]},}
这是我的CKEDITOR_在settings.py文件中配置的。仍然不走运。谢谢Tim,我找到了一些代码,我将它们复制到settings.py文件中,现在可以使用了。