Django CMS Custom Plugin不呈现模板

时间:2013-04-12 17:14:32

标签: django-cms

运行全新安装的django-cms 2.4.0-RC1,django 1.5.1和python 2.7。我试图用单个字段创建一个非常简单的自定义插件。该插件在管理员中注册并正常工作。它成功存储在数据库中。它只是没有在我的模板中呈现。

我已经验证了render_template路径,并尝试使用硬编码的绝对路径。我已经尝试覆盖CMSSelectDegreeLevelPlugin中的render方法。

我忽略了一些明显的东西吗?我之前(在不同版本的django-cms中)制作了非常相似的插件并没有遇到任何麻烦。

models.py:

from cms.models.pluginmodel import CMSPlugin
from django.db import models


class SelectDegreeLevel(CMSPlugin):
    degree_level = models.CharField('Degree Level', max_length=50)

cms-plugins.py

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from django.utils.translation import gettext_lazy as _
from models import SelectDegreeLevel


class CMSSelectDegreeLevelPlugin(CMSPluginBase):
    model = SelectDegreeLevel
    name = _('Degree Level')
    render_template = "cms/plugins/select_degree_level.html"

plugin_pool.register_plugin(CMSSelectDegreeLevelPlugin)

select_degree_level.html

<h1>static text test {{ instance.degree_level }}</h1>

1 个答案:

答案 0 :(得分:0)

我认为你的领域不在上下文中。我通常就是这样做的。将此功能添加到CMSSelectDegreeLevelPlugin类

# Way to decide what comes in the context
def render(self, context, instance, placeholder):
        extra_context = {
            'degree_level': instance. degree_level,
        }
        context.update(extra_context)
        return context

# Simplest Way
def render(self, context, instance, placeholder):
    context['instance'] = instance
    return context

Also you can read more here in docs