Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

linux

mako

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?

like image 827
user713713 Avatar asked Oct 29 '14 20:10

user713713


People also ask

What are Mako templates?

Well, you’re in luck because enter Mako templates. Mako is a template library and a Python Sever Page language, allowing content such as HTML, XML, and text to be integrated with Python.

How do I use Mako in Python?

The simplest way to use Mako in your Python project is through the provided Template class. from mako.template import Template tmp = Template ("hello $ {name}") print (tmp.render (name="world!")) We can also write out the templates using Mako’s syntax in a separate file and load it in.

How many examples of Mako exceptions are there?

The following are 30 code examples of mako.exceptions.TemplateLookupException () . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

How do I vote up or down on Mako examples?

You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mako.exceptions , or try the search function .


1 Answers

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

like image 58
user713713 Avatar answered Sep 23 '22 17:09

user713713