【问题标题】:extending django cms - plugin class - understanding issue扩展 django cms - 插件类 - 理解问题
【发布时间】:2014-11-26 14:15:44
【问题描述】:

我正在通过Extending the CMS 阅读。

我在理解一些细节方面有一些问题:

我需要创建一个插件类。例如PollPlugin。

class PollPlugin(CMSPluginBase):
  model = PollPluginModel                 # Model where data about this plugin is saved
  name = _("Poll Plugin")                 # Name of the plugin
  render_template = "polls/plugin.html"   # template to render the plugin with

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

plugin_pool.register_plugin(PollPlugin) # register the plugin

我的问题:

  1. 在这种情况下instance 是什么?
  2. 这两个插件类的目标是什么? PollPluginModel 和 PollPlugin。
  3. Apphook 和 Plugin 之间的区别

感谢任何答案

【问题讨论】:

    标签: django django-cms


    【解决方案1】:

    Django-CMS 插件可能有点棘手。

    instance 在这种情况下是PollPlugin 的一个实例。

    PollPlugin 用作“连接”模型,将PollPluginModel 的一个或多个实例与插件实例 (PollPlugin) 相关联,然后将其分配给页面上的占位符。

    “apphook”是一个回调,它告诉 Django-CMS 它需要将视图处理移交给您的应用模块中的其他用户指定的 URL 模式。

    “插件”是可以分配给占位符的模型。

    【讨论】:

    • 谢谢。我的第二个想法是如果没有回复就给你发邮件。Vielen Dank :) 现在我明白了。
    • 咬! Immer froh zu helfen。
    • 嘿,布兰登,还有一个问题。 render 在这里做什么?
    • render 在页面输出之前添加插件实例、占位符以及您需要添加到模板上下文的任何其他内容。
    • 谢谢,我明白了。但还有一个问题:Plugin 如何在渲染过程中找到它的 apphook?在定义它们时我没有看到任何连接:(
    猜你喜欢
    • 1970-01-01
    • 2013-05-26
    • 2010-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 2011-01-27
    • 1970-01-01
    相关资源
    最近更新 更多