如何继承和修改标准的Django CMS Link插件?

时间:2015-01-20 21:25:08

标签: python django python-2.7 django-cms

我尝试过以下代码:

cms_plugins.py:

from djangocms_link.cms_plugins import LinkPlugin
from .models import SecondaryNavigationLink

class SecondaryNavigationLinkPlugin(LinkPlugin):
    name = _("Secondary Navigation Link")
    model = SecondaryNavigationLink

    def render(self, context, instance, placeholder):
        context.update({
            'instance': instance,
            'placeholder': placeholder,
        })
        return context

plugin_pool.register_plugin(SecondaryNavigationLinkPlugin)

models.py:

from djangocms_link.models import Link

class SecondaryNavigationLink(Link):
    pass

我可以看到我的链接插件在通用部分下的cms控制面板上呈现,但是一旦我点击保存,我看到请求中的500间隔服务器错误,Django CMS呈现这样的插件块

Secondary Navigation Link <Empty>

我无能为力。

1 个答案:

答案 0 :(得分:0)

事实证明,我通过覆盖Link插件的默认渲染方法犯了一个愚蠢的错误:

https://github.com/divio/djangocms-link/blob/master/djangocms_link/cms_plugins.py#L21

通过简单地摆脱我的渲染功能来解决这个问题:

class SecondaryNavigationLinkPlugin(LinkPlugin):
    name = _("Secondary Navigation Link")
    model = SecondaryNavigationLink

    # No more render