【发布时间】:2018-10-28 03:47:02
【问题描述】:
遵循https://django-ckeditor.readthedocs.io/en/latest/ 中提到的每个步骤,但是当我查看表单时,我没有得到任何编辑器。我也确实运行了“python manage.py collectstatic”
ckeditor 特有的settings.py。
INSTALLED_APPS = [
'ckeditor',
'ckeditor_uploader',
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,"static")
CKEDITOR_BASEPATH = STATIC_ROOT+"/ckeditor/ckeditor"
CKEDITOR_UPLOAD_PATH = "ck_uploads/"
CKEDITOR_IMAGE_BACKEND = "pillow"
MEDIA_URL = STATIC_URL+'media/'
MEDIA_ROOT = os.path.join(STATIC_ROOT,'media')
urls.py
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
forms.py
from ckeditor.widgets import CKEditorWidget
class BlogPostForm(forms.ModelForm):
class Meta():
model = BlogPost
fields = ('title','brief','content','accept_comments','is_public')
brief = forms.CharField(widget=CKEditorWidget())
content = forms.CharField(widget=CKEditorWidget())
到目前为止没有任何建议有效(包括将小部件定义移出 Meta)。
我正在自定义呈现表单,这就是该字段在表单中呈现的方式。
{{ form.details }}
使用{{ form.as_p }} 渲染整个表单也没有任何区别。
这是我使用 Chrome 开发者工具时 HTML 字段显示的内容 --> 元素。
<textarea cols="40" id="id_details" name="details" rows="10" required="" data-processed="0" data-config="{"skin": "moono-lisa", "toolbar_Basic": [["Source", "-", "Bold", "Italic"]], "toolbar_Full": [["Styles", "Format", "Bold", "Italic", "Underline", "Strike", "SpellChecker", "Undo", "Redo"], ["Link", "Unlink", "Anchor"], ["Image", "Flash", "Table", "HorizontalRule"], ["TextColor", "BGColor"], ["Smiley", "SpecialChar"], ["Source"]], "toolbar": "Custom", "height": 291, "width": 835, "filebrowserWindowWidth": 940, "filebrowserWindowHeight": 725, "toolbar_Custom": [["Bold", "Italic", "Underline"], ["NumberedList", "BulletedList", "-", "Outdent", "Indent", "-", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"], ["Link", "Unlink"], ["RemoveFormat", "Source"]], "language": "en-us"}" data-external-plugin-resources="[]" data-id="id_details" data-type="ckeditortype"></textarea>
【问题讨论】:
标签: python-3.x django-forms ckeditor5