RichTextField 无法使用 Wagtail 2.0 中的 Draftail 进行编辑

RichTextField uneditable with Draftail in Wagtail 2.0

我将我的网站(开发版)更新为 wagtail 2.0,并且我页面的所有 RichTextField 属性都完全无法编辑,Draftail.js。我在 settings.py:

中添加了以下几行
WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea'
    }
}

恢复到以前的 Hallo.js 编辑器,它可以正常工作。但是当我删除它时,已经保存的内容不再打印,也没有编辑功能了。这是模型定义:

from django.db import models

from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel

class BlogIndexPage(Page):
    intro = RichTextField(blank=True,features=[
        'h2',
        'h3',
        'ol',
        'ul',
        'bold',
        'italic',
        'link'
    ])

content_panels = Page.content_panels + [
    FieldPanel('intro', classname="full")
]

还有我的 settings.py 文件:

import os
from decouple import config

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')

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

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_extensions',
    'django.contrib.sitemaps',

    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.core',

    'modelcluster',
    'taggit',

    'homepage',
    'blog',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    'wagtail.core.middleware.SiteMiddleware',
    'wagtail.contrib.redirects.middleware.RedirectMiddleware',
]

ROOT_URLCONF = 'lsvwebsite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIR],
        '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 = 'site.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': config('NAME_DB'),
        'USER': config('USER_DB'),
        'PASSWORD': config('PASSWORD_DB'),
        'HOST': config('HOST_DB'),
        'PORT': '',
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-  validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.11/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.11/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

#media files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

#wagtail site name
WAGTAIL_SITE_NAME = 'Site Name'

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea'
    }
}

新的 Draftail.js 编辑器看起来像个问题…

编辑 1:使用 Firefox Quantum 58.0.2 在 Web 控制台中打印错误

TypeError: o.a.createElement is not a function    draftail.js:1:241051
TypeError: window.draftail is undefined    edit:560:1

编辑 2:使用 Opera 51.0 在 Web 控制台中打印错误

draftail.js:1 Uncaught TypeError: o.a.createElement is not a function
    at Object.<anonymous> (draftail.js:1)
    at t (vendor.js:1)
    at Object.<anonymous> (draftail.js:1)
    at t (vendor.js:1)
    at Object.<anonymous> (draftail.js:1)
    at t (vendor.js:1)
    at window.webpackJsonp (vendor.js:1)
    at draftail.js:1
(index):560 Uncaught TypeError: Cannot read property 'initEditor' of  undefined
    at (index):560
rangy-core.js:80 [Deprecation] The behavior that Selection.addRange() merges existing Range and the specified Range was removed. See  https://www.chromestatus.com/features/6680566019653632 for more details.
(anonymous) @ rangy-core.js:80

我相信我遇到了同样的问题,至少错误消息的标题是一样的,描述也很相似。对我有用的是再次删除静态 wagtailadmin javascript 目录和 运行 collectstatic。虽然我仍然不知道到底是什么导致了这个错误。

所以,我首先尝试清除缓存,但没有用。 然后我想起来我习惯设置firefox关闭时自动清除缓存,所以我检查了我的firefox设置,确实是这样设置的。然后,我尝试了@fixgoats 解决方案,我清除了不是我自己创建的静态文件和 运行 collectstatic,它没有用。我记得我不应该在开发环境中 运行 collectstatic,所以我删除了它们而没有再次 运行ning collectstatic,它没有用,所以我清除了缓存(因为我没有关闭 firefox在此过程中)并且它在那里起作用。

我的猜测是,我将过时的静态文件直接存储在 dev 静态目录中,而 firefox 正在使用并缓存这些过时的文件(一个问题隐藏另一个)。现在,一切正常,非常感谢大家。