微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在插件Django CMS中添加插件

如何解决如何在插件Django CMS中添加插件

我已经创建了一个类似的插件 plugin_pool。 但是我不知道如何在此插件添加一个插件

解决方法

您的插件需要设置allow_children属性,然后,您可以通过在child_classes列表中指定插件类来控制该插件可以拥有的子级(如果需要)。见下文。

from .models import ParentPlugin,ChildPlugin

@plugin_pool.register_plugin
class ParentCMSPlugin(CMSPluginBase):
    render_template = 'parent.html'
    name = 'Parent'
    model = ParentPlugin
    allow_children = True  # This enables the parent plugin to accept child plugins
    # You can also specify a list of plugins that are accepted as children,# or leave it away completely to accept all
    # child_classes = ['ChildCMSPlugin']

    def render(self,context,instance,placeholder):
        context = super(ParentCMSPlugin,self).render(context,placeholder)
        return context


@plugin_pool.register_plugin
class ChildCMSPlugin(CMSPluginBase):
    render_template = 'child.html'
    name = 'Child'
    model = ChildPlugin
    require_parent = True  # Is it required that this plugin is a child of another plugin?
    # You can also specify a list of plugins that are accepted as parents,# or leave it away completely to accept all
    # parent_classes = ['ParentCMSPlugin']

    def render(self,placeholder):
        context = super(ChildCMSPlugin,placeholder)
        return context

您的父级插件模板随后需要将子级渲染成这样;

{% load cms_tags %}

<div class="plugin parent">
    {% for plugin in instance.child_plugin_instances %}
        {% render_plugin plugin %}
    {% endfor %}
</div>

它的文档在您链接到的页面上;

http://docs.django-cms.org/en/latest/how_to/custom_plugins.html#nested-plugins

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。