M
M
michael ivanov2015-07-16 19:00:19
Django
michael ivanov, 2015-07-16 19:00:19

Which wysiwyg editor to implement in Django 1.8?

Hello to all! I ask for your help. I read a lot of mana on what wysiwyg editor to implement in Django. Most of them are in English, which I don’t understand at all (But these manuals (those in Russian) describe either old versions of the editors and the framework, or even not working solutions at all.
What a wysiwyg with the ability to upload images and clean up the formatting of the copied text put on the site?If it's not hard for you - explain how to do
it.Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
michael ivanov, 2015-07-18
@Pauchenkov

Good evening everyone! Finally managed to connect the wysiwyg editor. I want to share for the future with those who have not done this yet :) Maybe someone will come in handy.
So I connected ckeditor like this:
1) Install django-ckeditor with this command: pip install django-ckeditor
2) Add ckeditor to the INSTALLED_APPS list

INSTALLED_APPS = (
    ................. ,
    'ckeditor',
)

3) Set up MEDIA_ROOT, MEDIA_URL, STATIC_ROOT, STATIC_URL, STATIC_DIRS, STATICFILES_FINDERS
after the line import os, if suddenly you don't have it set, write down the path of the base directory
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
, but if you have a value written differently, I advise you not to touch this (existing) line, but simply add another one under it, calling it not BASE_DIR, but in a different way (for example: _PATH).
Set MEDIA_ROOT and MEDIA_URL:
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')
MEDIA_URL = '/media/'

Set STATIC_ROOT, STATIC_URL, STATICFILES_DIRS and STATICFILES_FINDERS:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/statics/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'statics'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

4) Set the paths and settings of CKEDITOR, namely: CKEDITOR_UPLOAD_PATH, CKEDITOR_IMAGE_BACKEND, CKEDITOR_JQUERY_URL, CKEDITOR_CONFIGS
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'

# CKEDITOR_CONFIGS по сути необязательны. Они влияют на тулбар редактора. Если выключите - будет очень мало инструментов для работы с текстом. После полной настройки - попробуйте с ними поиграться. Возможно найдете для себя какой-то более оптимальный вариант настроек!
CKEDITOR_CONFIGS = {
    "default": {
        "removePlugins": "stylesheetparser",
        'allowedContent': True,
        'toolbar_Full': [
        ['Styles', 'Format', 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ],
        ['Image', 'Flash', 'Table', 'HorizontalRule'],
        ['TextColor', 'BGColor'],
        ['Smiley','sourcearea', 'SpecialChar'],
        [ 'Link', 'Unlink', 'Anchor' ],
        [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language' ],
        [ 'Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates' ],
        [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ],
        [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ],
        [ 'Maximize', 'ShowBlocks' ]
    ],
    }
}

5) Setting up URLs
............. ,
url(r'^ckeditor/', include('ckeditor.urls')),

Here is the FULL OPTION:
urlpatterns = [
............... ,
url(r'^ckeditor/', include('ckeditor.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
6) ALWAYS RUN collectstatic!!!
In the terminal, type: python manage.py collectstatic
Then confirm by typing yes !
7) In the models file (models.py), we must first make an import:
8) There is little left. Now, in order for the field to have a WYSIWYG editor in the admin panel, you need to manually specify RichTextField instead of models.CharField (TextField and other fields).
Here is an example of how it should be:
title_story = RichTextField(max_length=255, verbose_name="Название")
anons = RichTextField(max_length=1000, null=True, blank=True, verbose_name="Анонс")
story = RichTextField(verbose_name="Полная статья")
... ну и так далее ....

S
sim3x, 2015-07-16
@sim3x

Learn English otherwise we will solve all the tasks
django-summernote

U
un1t, 2015-07-16
@un1t

Yes, even in Chinese, what's the difference, there are a lot of translators.
I am using ckeditor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question