我创建了一个“模型”的“视图”,显示了最后五个元素。我如何创建CMS插件,我可以将其放入“占位符”?
答案 0 :(得分:5)
为了创建一个可以在占位符中使用的django-cms插件,你have to create a subclass of CMSPluginBase。在您的子类中,您应该覆盖渲染方法,以实现自定义渲染。
另见本例(摘自文档):
# myapp/cms_plugins.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from polls.models import PollPlugin as PollPluginModel
from django.utils.translation import ugettext as _
class PollPlugin(CMSPluginBase):
model = PollPluginModel # Model where data about this plugin is saved
name = _("Poll Plugin") # Name of the plugin
render_template = "polls/plugin.html" # template to render the plugin with
def render(self, context, instance, placeholder):
context.update({'instance':instance})
return context
plugin_pool.register_plugin(PollPlugin) # register the plugin