Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'get_default_renderer'

Im installing the ckeditor app in my django, follow the instructions from ckeditor documentation at the moment of run the runserver, doesn't works, well,I get the error when add the from ckeditor.fields import RichTextField in the models.py

This is my settings.py:

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'suj4$h^8p&x#p_#i$_p&z@&d^46=#7kf6a#_tkqh68er^)872s'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'suit',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'ckeditor',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# Django Suit configuration example
SUIT_CONFIG = {
     'ADMIN_NAME': 'Inicia sesión cabrón',
     'HEADER_DATE_FORMAT': 'l, j. F Y',
     'HEADER_TIME_FORMAT': 'H:i',
     'SEARCH_URL': '/admin/auth/user/',
     'MENU_ICONS': {
        'sites': 'icon-leaf',
        'auth': 'icon-lock',
     },
     'MENU_OPEN_FIRST_CHILD': True, # Default True
     'MENU_EXCLUDE': ('auth.group',),
     'MENU': (
         'sites',
         {'app': 'auth', 'icon':'icon-lock', 'models': ('user', 'group')},
         {'label': 'Settings', 'icon':'icon-cog', 'models': ('auth.user', 'auth.group')},
         {'label': 'Blog', 'icon':'icon-play-circle', 'url': 'blog.post'},
     ),
}

CKEDITOR_BASEPATH = {
    '/static/ckeditor/ckeditor/',
}

Error:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7ff7671a0268>
Traceback (most recent call last):
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/francisco/work/django/blog/Django-Blog/blog/models.py", line 2, in <module>
    from ckeditor.fields import RichTextField
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/ckeditor/fields.py", line 6, in <module>
    from .widgets import CKEditorWidget
  File "/home/francisco/work/django/blog/Django-Blog/.env/lib/python3.6/site-packages/ckeditor/widgets.py", line 12, in <module>
    from django.forms.widgets import get_default_renderer
ImportError: cannot import name 'get_default_renderer'
like image 212
FranzSif Avatar asked Jul 27 '18 21:07

FranzSif


2 Answers

I met the same problem. It's due to the version of ckeditor and the version of Django you use. My current django==1.9.8 which is not supported by django-ckeditor==5.6.1

My solution :

pip install django-ckeditor==5.3.0

If your Django version is between 1.8 and 1.10, this may work as well.

The Author has fixed this issue and updated in Github recently.

like image 187
cheng Avatar answered Sep 21 '22 16:09

cheng


There is a version difference between the version of ckeditor you are using and the version used in the project. This same error was faced by me when I tried to run a pre-existing project.

like image 37
Vishal Baghel Avatar answered Sep 22 '22 16:09

Vishal Baghel