Take the 2-minute tour ×

They both let you stick some mako-rendered content into another one. Both let you pass in arguments.

Is there a performance difference between the two? A philosophical one?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Def is for defining functions in the template, while include executes another file.

The mako documentation summarizes thus:

Calling a <%def> from another template is something like using an <%include> – except you are calling a specific function within the template, not the whole template.

(from http://docs.makotemplates.org/en/latest/defs.html)

Of course, <%include> involves another file, you can call a <%def> from the same file it is defined in.

share|improve this answer
Right, I get that, but is the advantage just that include requires you to write lots of small .mak files while def lets you write one larger one? Is it just a difference in what you think clean code looks like? –  Rob Crowell Dec 3 '12 at 23:09
Just using <%include> requires you to write lots of small mako files. But if your code is large enough, you don't want to use only <%def> either. You want to use <%def> for functions and split your functions into appropriate modules that are <%include>d, just like you would do (hopefully) with collections in other languages like C, Javascript, Python, ASP, etc. –  Joshua D. Boyd Dec 4 '12 at 21:54
Interesting, thanks for your thoughts. –  Rob Crowell Dec 18 '12 at 4:08
add comment

Your Answer


