3

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>
4

1 に答える 1

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

また、こちらのドキュメントで詳細を読むことができます

于 2013-04-17T14:55:39.923 に答える