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?
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.
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.
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.
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 .
After posting this I found it works if the 4th line is mytemplate = mylookup.get_template('content.html.mako')
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With