mako - loading templates from files, please help :)

Joined
Aug 19, 2010
Messages
2
Reaction score
0
Hello there.
I'm new to python and currently trying to use mako templating.
I want to be able to take an html file and add a template to it from another html file.
Let's say I got this index.html file:

Code:
<html>
<head>
  <title>Hello</title>
</head>
<body>    
    <p>Hello, ${name}!</p>
</body>
</html>


and this name.html file:

Code:
world


(yes, it just has the word world inside).

I want the ${name} in index.html to be replaced with the content of the name.html file.

I've been able to do this without the name.html file, by stating in the render method what name is, using the following code:

Code:
@route(':filename')
def static_file(filename):    
    mylookup = TemplateLookup(directories=['html'])
    mytemplate = mylookup.get_template('hello/index.html')
    return mytemplate.render(name='world')


This is obviously not useful for larger pieces of text.. Now all I want is to simply load the text from name.html, but haven't yet found a way to do this.
Any help is much appreciated :D
 
Joined
Aug 19, 2010
Messages
2
Reaction score
0
solution

this code seems to eventually work:

Code:
@route(':filename')
def static_file(filename):    
    mylookup = TemplateLookup(directories=['.'])
    mytemplate = mylookup.get_template('index.html')
    temp = mylookup.get_template('name.html').render()
    return mytemplate.render(name=temp)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top