gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:19:29 27 4
gpt4 key购买 nike

我将我的网站(开发版本)更新为 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

最佳答案

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

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

关于python - Wagtail 2.0 中的 RichTextField 无法使用 Draftail 进行编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49088302/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com