在Django CM中将每个插件单独封装

2024-05-13 08:53:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我想包装每一个插件,是添加到我的djangocms在特定的HTML页面。所以,从模板开始

<body>
  {% block content %}{% endblock content %}
<body>

和TextPlugin元素

<p>Lorem ipsum</p>

以及

<p>dolor sit amet</p>

要实际呈现为如下所示的页面:

<body>
  <div class="wrapper"><p>Lorem ipsum</p></div>
  <div class="wrapper"><p>dolor sit amet</p></div>      
</body>

我看过djangocms-cascade,但它似乎并没有提供我想要的东西,而且在我的django cms3.2.1上迁移失败了。你知道吗


Tags: div插件模板htmldjangocmsbody页面content
1条回答
网友
1楼 · 发布于 2024-05-13 08:53:22

看看django cms的插件处理器。见http://docs.django-cms.org/en/3.2.2/how_to/custom_plugins.html#plugin-processors

在你的设置.py地址:

CMS_PLUGIN_PROCESSORS = (
    'yourapp.cms_plugin_processors.wrap_plugin',
)

在你的yourapp.cms\u插件\u处理器.py码:

from django.template import Context, Template

def wrap_plugin(instance, placeholder, rendered_content, original_context):
    t = Template('<div class="wrapper">{{ content|safe }}</div>')
    c = Context({
        'content': rendered_content
    })
    return t.render(c)

相关问题 更多 >