[英]Can't get CKEditor plugins to work in django
I am trying to get the CKEditor plugin, codesnippet, to work in the django admin but am unable to. 我正在尝试让CKEditor插件codenippet在django admin中工作,但无法运行。 CKEditor works if I don't define any CKEDIT_CONFIGS in my settings.py.
如果我在settings.py中未定义任何CKEDIT_CONFIGS,则CKEditor可以工作。 It also works if take out the "extraPlugins" line (and it successfully will adjust the height and width as defined in the CKEDITOR_CONFIGS section).
如果取出“ extraPlugins”行,它也将起作用(成功地将按照CKEDITOR_CONFIGS部分中的定义调整高度和宽度)。
I installed CKEditor using the instructions here: https://github.com/shaunsephton/django-ckeditor 我按照这里的说明安装了CKEditor: https : //github.com/shaunsephton/django-ckeditor
CKeditor is located in /static/ckeditor and codesnippet is in /static/ckeditor/plugins/ CKeditor位于/ static / ckeditor中,而codenippet位于/ static / ckeditor / plugins /中
In my settings.py 在我的settings.py中
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_JQUERY_URL = '/static/js/jquery-2.1.1.min.js'
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'Full',
'height': 400,
'width': 900,
'removePlugins': 'stylesheetparser',
'extraPlugins': 'codesnippet',
},
}
My admin.py 我的管理员
from django.contrib import admin
from blog.models import Article, Category
from django.utils import text
from django import forms
from ckeditor.widgets import CKEditorWidget
class ArticleAdminForm(forms.ModelForm):
body = forms.CharField(widget=CKEditorWidget())
class Meta:
model = Article
I have also tried using just 'plugins' instead of 'extraPlugins' (although this not recomended), but get the same result (which is it breaks CKEditor and the filed doesn't display at all in the admin). 我也尝试过仅使用“插件”而不是“ extraPlugins”(尽管不建议这样做),但得到的结果相同(这会打断CKEditor,并且文件在管理员中根本不会显示)。
Thanks in advance for your help! 在此先感谢您的帮助!
EDIT 11/26/14 编辑11/26/14
OK so this still isn't working. 确定,因此仍然无法正常工作。 I am pretty sure the problem is this (from the nginx error log)
我很确定问题是这样的(来自nginx错误日志)
2014/11/26 14:07:20 [error] 3265#0: *1 open() "/srv/www/mysite/static//ckeditor/ckeditor/plugins/codesnippet/plugin.js" failed
That path isn't right (erroneous double black slash and an extra "ckeditor" directory"). 该路径不正确(错误的双黑斜杠和额外的“ ckeditor”目录”)。
My settings.py now looks like this. 我的settings.py现在看起来像这样。
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_JQUERY_URL = '/static/js/jquery-2.1.1.min.js'
CKEDITOR_CONFIGS = {
'default': {
'toolbar':[ ['CodeSnippet', ], ],
'height': 400,
'width': 900,
'removePlugins': 'stylesheetparser',
'extraPlugins': 'codesnippet',
},
}
The Extra Plugins line is what is causing the nginx error, I have no idea where it is getting that path. Extra Plugins行是导致nginx错误的原因,我不知道它在哪里获取该路径。
Below is more further information that may be helpful. 以下是更多有用的信息。
This is my full admin.py file 这是我的完整admin.py文件
from django.contrib import admin
from blog.models import Article, Category
from django.utils import text
from django import forms
from django.db import models
from ckeditor.widgets import CKEditorWidget
class ArticleAdminForm(forms.ModelForm):
body = forms.CharField(widget=CKEditorWidget())
class Meta:
model = Article
class ArticleAdmin(admin.ModelAdmin):
form = ArticleAdminForm
admin.site.register(Article, ArticleAdmin)
admin.site.register(Category)
I have copied the following lines into my ckedit.js file and dragged over the appropriate folders in the the plugins folder. 我已将以下行复制到我的ckedit.js文件中,并将其拖到plugins文件夹中的相应文件夹上。
config.extraPlugins = 'dialog';
config.extraPlugins = 'widget';
config.extraPlugins = 'dialogui';
config.extraPlugins = 'lineutils';
config.extraPlugins = 'clipboard';
config.extraPlugins = 'codesnippet';
config.toolbar_Full.push(['codesnippet']);
EDIT 12/1/14 编辑14/1/14
Nginx config file (as requested) Nginx配置文件(根据要求)
server {
listen 8080;
server_name mysite.com;
access_log /srv/www/mysite/logs/access-dev.log;
error_log /srv/www/mysite/logs/error-dev.log;
charset utf-8;
#Django admin css
location /static/admin {
alias /srv/www/mysite/static/admin;
}
#Django static files
location /static {
alias /srv/www/mysite/static/;
}
#Django media files
location /media {
alias /srv/www/mysite/media/;
}
#Uwsgi handles all other requests
location / {
auth_basic "Restricted";
auth_basic_user_file /srv/www/mysite/.nginxpwd;
uwsgi_pass unix:/var/uwsgi/uwsgi_at-dev.sock;
include uwsgi_params;
}
}
EDIT 12/3/14 编辑14/3/14
Full nginx error: 完整的Nginx错误:
2014/11/26 14:36:16 [error] 3461#0: *1 open() "/srv/www/mysite/static//ckeditor/ckeditor/plugins/codesnippet/plugin.js" failed (2: No such file or directory), client: 71.235.164.91, server: 104.131.36.141,, request: "GET /static/ckeditor/ckeditor/plugins/codesnippet/plugin.js?t=E7KD HTTP/1.1", host: "mysite:8080", referrer: "http://mysite:8080/admin/blog/article/3/"
In my settings.py 在我的settings.py中
MEDIA_ROOT = '/srv/www/mysite/media/'
MEDIA_URL = '/media/'
STATIC_ROOT = '/srv/www/mysite/static'
STATIC_URL = '/static/'
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_JQUERY_URL = '/static/js/jquery-2.1.1.min.js'
The Code Snippet plugin has various dependencies each of which has sub-dependencies, ie: 代码片段插件具有各种依赖性,每个依赖性都有子依赖性,即:
I had to as a minimum add Code Snippet, Widget and Line Utils in the ckeditor/plugins path to get it to work, as well as use the following setting to get the button to show up in the toolbar. 我至少必须在ckeditor / plugins路径中添加代码片段,小部件和Line Utils才能使其正常工作,并使用以下设置来使该按钮显示在工具栏中。
CKEDITOR_CONFIGS = {
'default': {
'toolbar':[ ['CodeSnippet', ], ],
'height': 400,
'width': 900,
'removePlugins': 'stylesheetparser',
'extraPlugins': 'codesnippet',
},
}
So once all your plugin dependencies are all installed it should work. 因此,一旦所有插件依赖项都安装完毕,它应该可以工作。
I've been battling the same problem for days and I guess I found a workaround for this problem. 我一直在同一个问题作斗争几天,我想我找到了解决此问题的方法。
As you have noticed too, it tries to read this "static/ckeditor/ckeditor/plugins/codesnippet/plugin.js" javascript but it cannot locate it, even if you've put the plugin in the folder of "YOUR_PROJECT_DIR/static/ckeditor/ckeditor/plugins". 您也已经注意到,它会尝试读取此“ static / ckeditor / ckeditor / plugins / codesnippet / plugin.js” javascript,但即使将插件放在“ YOUR_PROJECT_DIR / static / CKEditor的/ CKEditor的/插件”。 The reason is, django-ckeditor is not searching the static directory in your project directory, it is searching it own static directory in its own path in site-packages.
原因是django-ckeditor不在项目目录中搜索静态目录,而是在站点包中其自身路径中搜索自己的静态目录。 As a result, you may do the following as a workaround.
如此一来,您可以作为解决方法执行以下操作。
PS: PS:
I fought with this for ages trying to install the plugins and dependencies manually. 我为此尝试了很多年,试图手动安装插件和依赖项。
In the end, I packaged up all the plugins I wanted with CKEditor Builder and dropped it into a ckeditor directory in my STATICFILES_DIRS. 最后,我用CKEditor Builder打包了所有想要的插件,并将其放入STATICFILES_DIRS的ckeditor目录中。 /static/ckeditor/ckeditor/plugins & .js etc
/ static / ckeditor / ckeditor / plugins和.js等
I am using CKEditor within https://github.com/django-blog-zinnia/zinnia-wysiwyg-ckeditor so my settings look like..... 我在https://github.com/django-blog-zinnia/zinnia-wysiwyg-ckeditor中使用CKEditor,所以我的设置看起来像.....
CKEDITOR_UPLOAD_PATH = 'uploads'
CKEDITOR_IMAGE_BACKEND = 'pillow'
CKEDITOR_CONFIGS = {
'zinnia-content': {
'toolbar': 'Zinnia',
"extraPlugins":'codesnippet',
"codeSnippet_theme": "monokai_sublime",
'skin': 'moono-dark',
'toolbar_Zinnia': [
['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
['Undo', 'Redo'],
['Scayt'],
['Link', 'Unlink', 'Anchor'],
['Image', 'Table', 'HorizontalRule', 'SpecialChar'],
['Source'],
['Maximize', 'Resize'],
'/',
['Bold', 'Italic', 'Underline', 'Strike',
'Subscript', 'Superscript', '-', 'RemoveFormat'],
['NumberedList', 'BulletedList', '-',
'Outdent', 'Indent', '-', 'Blockquote'],
['Styles', 'Format'],['CodeSnippet'],
'/',
['Smiley', 'About', 'Preview', 'Templates' ],
],
},
}
So hopefully, without Zinnia, your settings would look like.... 因此,希望没有Zinnia,您的设置应该像...
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'Full',
"extraPlugins":'codesnippet',
"codeSnippet_theme": "monokai_sublime",
'skin': 'moono-dark',
},
}
This is a probably a different cause of the problem than what was original asked about, because it was a few years ago. 这可能是引起问题的原因与最初提出的原因不同,因为它是几年前的。 But a lot of plugins are not working with the latest release of django-ckeditor, version 5.1.0.
但是,许多插件无法与最新版本的django-ckeditor 5.1.0一起使用。
Took me ages to work out what was wrong - and it's just that the latest version does not include all the plugins. 我花了很长时间才弄清楚出了什么问题-只是最新版本并未包含所有插件。 If you pip uninstall and the install version 5.0.0, you get the full plugin suite.
如果您卸载并安装了5.0.0版本,则可以获得完整的插件套件。
Figure this might help someone who finds this thread. 图这可能会帮助找到此线程的人。
The actual cause is that plugin.js is not added by the CKEditor builder. 实际原因是CKEditor构建器未添加plugin.js。 I have no idea why that is, but each plugin's repository does have a plugin.js.
我不知道为什么,但是每个插件的存储库中都有一个plugin.js。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.