You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TimeWeb服务器中Django后台django-ckeditor无法工作求助

解决TimeWeb服务器上Django管理面板中django-ckeditor失效问题

环境信息

  • Python == 3.10
  • Django == 4.2.9
  • django-ckeditor == 5.9.0 - 6.7.0
  • 已按官方文档完成编辑器安装

配置代码

models.py

from ckeditor.fields import RichTextField
...
education = RichTextField(verbose_name='Education')
...

settings.py

INSTALLED_APPS = [
...
     'ckeditor'
]

STATIC_ROOT = '/home/.../public_html/static/'
STATIC_URL = '/static/'

出现的错误

Uncaught TypeError: Cannot set properties of undefined (setting 'dir')
at Object.d (VM1137 ckeditor.js:260:54)    
at w (VM1137 ckeditor.js:261:181)    
at Array.y (VM1137 ckeditor.js:261:336)    
at z (VM1137 ckeditor.js:261:420)    
at A.CKEDITOR.env.ie.f.$.onerror (VM1137 ckeditor.js:262:429)

异常路径(控制台输出)

  • experts.umiic.ru/admin/experts/expert/4/change/static/ckeditor/ckeditor/config.js?t=N5UC
  • experts.umiic.ru/admin/experts/expert/4/change/static/ckeditor/ckeditor/skins/moono-lisa/editor.css?t=N5UC
  • experts.umiic.ru/admin/experts/expert/4/change/static/ckeditor/ckeditor/lang/ru.js?t=N5UC

已尝试修改路径、重装应用,均无效。


解决方案

1. 修复静态资源路径问题

从控制台的异常路径能看出,静态资源URL被错误拼接在当前页面路径后,导致资源加载失败。需确保静态资源配置正确:

  • 执行静态资源收集命令,将ckeditor的静态文件同步到STATIC_ROOT目录:
python manage.py collectstatic
  • 检查TimeWeb服务器的静态资源路由配置,确保/static/路径正确映射到STATIC_ROOT目录(可通过控制面板或.htaccess文件配置)。

2. 强制指定CKEDITOR基础路径

在settings.py中添加配置,明确ckeditor静态资源的正确URL:

CKEDITOR_BASEPATH = "/static/ckeditor/ckeditor/"

3. 降级django-ckeditor版本

部分新版本与Django 4.2.x存在兼容性问题,可尝试降级到稳定版本:

pip install django-ckeditor==5.8.0

执行后重新运行collectstatic命令。

4. 检查静态资源权限

确保STATIC_ROOT下的ckeditor目录及文件拥有服务器可读权限:

chmod -R 755 /home/.../public_html/static/ckeditor
chmod -R 644 /home/.../public_html/static/ckeditor/*

内容的提问来源于stack exchange,提问作者Дмитрий Ипатов

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 05:04:59