如何从django视图创建django-cms插件?

Att*_*tio 0 django django-cms

我创建了一个"模型"的"视图",显示了最后五个元素.如何创建CMS插件,我可以将其放入"占位符"?

Bou*_*uke 5

为了创建可以在占位符中使用的django-cms插件,您必须创建CMSPluginBase的子类.在子类中,您应该覆盖render方法,以实现自定义呈现.

另请参见此示例(摘自文档):

# 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
Run Code Online (Sandbox Code Playgroud)