Search code examples
pythonlinuxmako

Why can't Mako locate a template beside the one that's including it?


Ok, running this in python:

from mako.lookup import TemplateLookup
from mako.template import Template
mylookup = TemplateLookup(directories=['/home/user/webapps/app/www/templates/'])
mytemplate = Template(filename='/home/user/webapps/app/www/templates/content.html.mako', lookup=mylookup)
print (mytemplate.render(title="Title", content={'hi'}))

When this is the begining of content.html.mako

## content.html.mako
<%inherit file="frame.html.mako"/>

Gives me this:

mako.exceptions.TemplateLookupException: Cant locate template for uri '/home/user/webapps/app/www/templates/frame.html.mako'

But the frame.html.mako is in the same directory as the content.html.mako, what's going on here?


Solution

  • After posting this I found it works if the 4th line is mytemplate = mylookup.get_template('content.html.mako') instead.