我创建了显示最后五个元素的“模型”的“视图”。如何创建可以放入“占位符”的 CMS 插件?
			
			1644 次
		
1 回答
            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
    于 2013-07-29T11:56:01.927   回答