Can't get CKEditor plugins to work in django

前端 未结 5 1850
后悔当初
后悔当初 2021-01-07 02:37

I am trying to get the CKEditor plugin, codesnippet, to work in the django admin but am unable to. CKEditor works if I don\'t define any CKEDIT_CONFIGS in my settings.py. It

5条回答
  •  孤独总比滥情好
    2021-01-07 03:16

    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". 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. As a result, you may do the following as a workaround.

    1. Build CKEditor with your plugins (extra plugins like CodeSnippet) using its Builder, replace CodeSnippet plugin and its dependencies with the standalone versions downloaded seperately from the CKEditor website. (The plugins do not have plugin.js file in their folder)
    2. Download it and unzip it, you will have a folder named 'ckeditor' with 'lang', 'plugins' as subfolders
    3. Replace the entire 'ckeditor' directory in 'static/ckeditor/ckeditor' in the folder of 'ckeditor' in your python's site-package folder. For example, your django-ckeditor is installed in "C:\Python27\Lib\site-packages", you'll see 'ckedior', replace the 'static/ckeditor/ckeditor' folder with your built ckeditor folder. Or you will have virtualenv or whatever, you may do it in its own site-packages.
    4. Add 'extraPlugins' settings as you already did in the problem description, and run python manage.py runserver and you will see 'CodeSnippet' plugin in your admin.

    P.S.:

    1. For 3., you can also copy this entire "site-packages/ckeditor" folder to your PROJECT_DIR, and make the replacement.
    2. To my experimentation, adding or removing plugins or making changes to the config files in "YOUR_PROJECT_DIR/static/ckeditor" does not show any effects, even if you remove the entire directory.
    3. Thus I guess there are still some settings we didn't make right, like STATIC_URL, STATIC_ROOT or something. I haven't figured out why since I am a beginner too and I didn't see what is wrong with your settings. I'll try to figure out the root cause and amend this answer if final "Solution" is found. Perhaps the package author 'shaunsephton' could easily figure it and lend some help. :D

提交回复
热议问题