Sheena Sheena - 14 days ago 5
Python Question

template lookup issues. What am i not understanding?

Background:

I have the following directory structure:

/absolute/path/to/templates
components/
component1.mak
component2.mak
template1.mak


The plan is for the templates in the template directory to
include
a bunch of components.

in template1.mak I have something like:

<%include file="xxx.mak"/>


where
xxx
is either
components/component1.mak
or just
component1.mak
(I tried both with different results, detailed below)

mylookup = TemplateLookup(directories=[yyy,])
oTemplate = Template(filename='/path/to/templates/template1.mak', lookup=mylookup)
oTemplate.render(args)


where yyy is either
'/absolute/path/to/templates'
or
'/absolute/path/to/templates/components'


The Problem:

No matter what combination of xxx and yyy values I use I get a template lookup exception. The value of yyy (the lookup path) doesn't seem to have any effect of the exception.

If xxx (the include tag path) is
'components\component1.mak'
the error says it can't find the file
/absolute/path/to/templates/components/component1.mak
. And if
xxx
is just
'component1.mak'
then the error is it can't find
/absolute/path/to/templates/component1.mak
.

The Question

How can I get mako to include the stuff in the components directory? And what am I missing or not understanding about template lookup?

Answer

Try putting a leading / when defining your xxx call in the template.

Comments