尝试使用ckeditor创建自定义插件,但在将此插件添加到cms页面时,其显示以下错误:
“value errorCannot assign”u''“:”Description.description“必须是”描述“实例:”
以下是我的models.py和cms_plugin.py文件。这里的问题是什么,感谢adavance?
models.py:
from cms.models import CMSPlugin
from django.db import models
from ckeditor.fields import RichTextField
from django.utils.translation import ugettext_lazy as _
class Description(CMSPlugin):
description=RichTextField(_('Description'),)
cms_plugins.py:
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from apps.cmsplugins.models import *
class DescriptionPlugin(CMSPluginBase):
model=Description
name=('Description')
render_template='cms/plugins/description.html'
def render(self,context,instance,placeholder):
print "contexttttttttttttttttttttttttttt"
context.update({
'instance': instance.description,
'object':instance,
'placeholder': placeholder,
})
return context
plugin_pool.register_plugin(DescriptionPlugin)
答案 0 :(得分:2)
我有同样的问题,现在我成功地解决了它 只关注使用(最喜欢的编辑器)ckeditor在Django-cms中实现RichTextBox的简单步骤:
models.py
from djangocms_text_ckeditor.models import AbstractText
class TipSlide(AbstractText):
pass
cms_plugins.py
from djangocms_text_ckeditor.cms_plugins import TextPlugin
from models import SlideModel, TipSlide
class TipSlidePlugin(TextPlugin):
name = u'Tip Slide Ads'
model = TipSlide
render_template = "slide/tipslide.html"
plugin_pool.register_plugin(TipSlidePlugin)
tipslide.html
<div>
<div class="container">
{{ body|safe }}<!-- The simple plugin -->
</div>
</div>
结果是:
答案 1 :(得分:0)
我认为你必须这样做,因为你没有在上下文instance.descripton
里面将Description实例传递给instance
def render(self,context,instance,placeholder):
print "contexttttttttttttttttttttttttttt"
context.update({
'instance': instance,
'object':instance,
'placeholder': placeholder,
})
return context
答案 2 :(得分:0)
由于Django用于子类模型的隐式一对一关系,因此不能将模型字段命名为与任何已安装的插件下层模型名称相同的名称。
见警告结束&#34; 3.5.Storing configuration&#34;部分:
http://docs.django-cms.org/en/3.0.1/extending_cms/custom_plugins.html#storing-configuration