Skip to content. | Skip to navigation

Personal tools


You are here: Home / Tips / Grok Framework

Grok Framework

Grok 扮演 Zope 3 的 wrapper 角色,它簡化 component 註冊流程,提供存取 Zope 3 的 API 功能。從 Plone 3.3 開始,可以透過 five.grok 使用 Grok 功能。但從 Plone 5 開始,Grok 或 collective.fastview 不再是預設推薦的機制。

Grok 是否該留在 Plone Core 裡,結論是不要,目的是減少技術相依性。

grok framework on developer documentation grok rules five.grok Core Grok Concepts

add viewlets 在 Plone 4.3 運作方式改變

Plone 4.3 環境下 static 目錄不再自動被掃描

ZCML allowed_attributes 對應方式


grok (five.grok, grokcore.view,, grokcore.component, grokcore.viewlet,, grokcore.annotation, martian?, plone.directives.form or plone.directives.dexterity) relations (from z3c.relationfield.schema import RelationList, RelationChoice)

Optional Extras: [grok] [relations] plone.directives.form is superfluos, all the directives were merged into plone.autoform and plone.supermodel. This works also in Plone 4.3 latest. IIRC the directives are deprecated anyway and are BBB imported in plone.directives.form.

  ' [grok]',

RelationList RelationChoice

Learning By Examples collective.pece


Plone 4.3 開始昇級並移除相依關係 Plone 5 文件移除 Grok 範例: collective.upload

  • 移除 five.grok,configure.zcml 移除 <grok:grok>
  • 移除 from five import grok
  • 手動註冊 static media folder
  • 透過 configure.zcml 註冊 View 和 Form
  • 透過 <browser:page> 來移除 grok.templatedir() 並註冊 View Class

移除相依關係範例: <grok.grok package="."> collective.twitter.portlets plone.directives.form collective.history collective.z3cform.datagridfield collective.fingerpointing collective.polls grok.context grok.implements grok.Adapter collective.dexteritytextindexer grok_component #1 #2 collective.z3cform.datagridfield



plone.directives.form 相依於 five.grok 和 grokcore.* 模組,已經不鼓勵使用,建議改用 plone.supermodel 和 plone.autoform,移除範例: collective.cover 在 Plone 4.3 預設已不支援

@grok.provider() 可用 @provider() 取代

from five import grok

from zope.component import provider

grok.implements() 等同於 implements() 或 @implementer()

from five import grok
class ImportantStuff(object):

from zope.interface import implementer
class ImportantStuff(object):

plone.directive.form Removal: collective.dexteritytextindexer

collective.cover 額外安裝了 grokcore.view grokcore.viewlet grokcore.component grokcore.annotation

Related content
Portlet Management