[Grok-dev] RFC: Making the automatic registration of templates more explicit

Jan-Wijbrand Kolman janwijbrand at gmail.com
Tue Jan 30 13:59:21 EST 2007

On 1/30/07, Philipp von Weitershausen <philipp at weitershausen.de> wrote:
> We've recently had a discussion about the automatic association of
> templates with models. There are people who think that it bares too much
> magic and should be done more explicitly.
> Martijn and others suggested that each fielsystem template would need a
> view class to go with it, hence making the existence of a view class the
> configuration knob for filesystem templates. While appreciating the
> explicitness of this approach, I think that will produce a lot of dead
> chickens if you have a lot of templates to publish.
> In an IRC discussion with Martijn just now, I suggested that
> * by default, filesystem templates would NOT be grokked automatically.
> They will, however, be grokked when there's an accompanying view class.
> * you can put a `grok.autotemplates()` statement into your module that
> will explicitly enable the automatic registration of templates *for that
> module*. Having this statement there, the currently implemented
> behaviour is carried out.
> With this in place, grok would only do the automation when it's
> explicitly told to do so. I think a one-liner directive is a decent
> compromise between explicitness and DRY. What do you guys think?

Personally I do not see a huge advantage to telling people "Template
files in the 'bar_templates' directory are automatically associated
with module 'bar'" over having to explain "To automatically associate
template files in the directory 'foo_templates' with the 'foo' module,
add the line 'grok.autotemplates()' to 'foo.py'". But admittedely,
this is based on intuition.

If we need a more explicit way of declaring templates for a module I
could imagine allowing the 'grok.template' directive to be used on a
module level. You would then get this:


  import grok

  class Qux(grok.Model):

Sure, if you have dozens of template-only views, you would have dozens
of 'grok.template(...)' declarations in the module. However, this
would, IMHO, still be readable just fine, allow for fine grained
control over what templates are associated without the
dead-chicken-ness of having a view class per template.

But probably you considered this option in the IRC discussion already?

Jan-Wijbrand Kolman

More information about the Grok-dev mailing list