Django tinyMC未能在管理面板中加载

2024-05-23 17:41:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我对django tinymce有意见。此模块在管理面板中加载不正确,可能也是正常形式。我使用python manage.py collectstatic收集静态文件。我正在用debug = False运行应用程序。我有两个错误:

Failed to load resource: the server responded with a status of 404 (Not Found)
Uncaught ReferenceError: tinyMCE is not defined

您可以在screenshoot中看到错误

设置:

INSTALLED_APPS = [
    'tinymce',
    ...
]

...

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

ENV_PATH = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/') 
MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/') 

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]


TINYMCE_JS_ROOT = os.path.join(STATIC_ROOT, "tiny_mce")
TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")

TINYMCE_DEFAULT_CONFIG = {
    'height': 360,
    'width': 1120,
    'cleanup_on_startup': True,
    'custom_undo_redo_levels': 20,
    'selector': 'textarea',
    'theme': 'modern',
    'plugins': '''
            textcolor save link image media preview codesample contextmenu
            table code lists fullscreen  insertdatetime  nonbreaking
            contextmenu directionality searchreplace wordcount visualblocks
            visualchars code fullscreen autolink lists  charmap print  hr
            anchor pagebreak
            ''',
    'toolbar1': '''
            fullscreen preview bold italic underline | fontselect,
            fontsizeselect  | forecolor backcolor | alignleft alignright |
            aligncenter alignjustify | indent outdent | bullist numlist table |
            | link image media | codesample |
            ''',
    'toolbar2': '''
            visualblocks visualchars |
            charmap hr pagebreak nonbreaking anchor |  code |
            ''',
    'contextmenu': 'formats | link image',
    'menubar': True,
    'statusbar': True,
}

和URL:

urlpatterns = [
    re_path(r'^tinymce/', include('tinymce.urls')),
    ...
]

编辑

我更新了代码,遵循@dirkgroten编写的指令,仍然得到了errorsHere is a tree of folderssettings.py在pystyle dir中


Tags: pathenvtrueurlosjslinkstatic
1条回答
网友
1楼 · 发布于 2024-05-23 17:41:51

对于所有静态/媒体设置,请记住:

  • ROOT是文件在存储器上的物理位置。在这里,您可以使用os.path.join之类的方法在文件系统中构建操作系统路径
  • URL是用于通过internet获取资源的url。这将由您的服务器(nginx)处理,它将把它转换为文件的实际位置,以便返回该文件

所以你的TINYMCE_JS_URL错了。它不是你磁盘上的路径,而是一个URL。应该是:

TINYMCE_JS_URL = STATIC_URL + "tinymce/tinymce.js"

相关问题 更多 >