Embedding a for inside an html template for substitution
Roland Koebler
r.koebler at yahoo.de
Tue Mar 5 12:16:43 EST 2013
Hi,
On Mon, Mar 04, 2013 at 09:22:38AM -0800, Ferrous Cranus wrote:
> can i just put the liens you provided me inside "files.html" and thwy
> will work?
>
> Thats pure pythjon code!
There are several template-engines where you more or less include
python-code into the template, e.g.: empy, mako, pyratemp
On Mon, Mar 04, 2013 at 08:56:14PM -0700, Michael Torrie wrote:
> Check out that link in my previous e-mail to a list of python templating
> engines. Choose one and try it. No I cannot provide any example code.
Here's an example for pyratemp (where I'm the author ;)):
files.html:
<table>
<tr><th>@!title!@</th></tr>
<!--(for e in mylist)-->
<tr><td>@!e!@</td></tr>
<!--(end)-->
</table>
files.py:
import pyratemp
t = pyratemp.Template(filename="files.html")
result = t(title="title ...", mylist=["entry 1", "entry 2", "entry 3"])
print result.encode("ascii", 'xmlcharrefreplace')
On Mon, Mar 04, 2013 at 08:56:14PM -0700, Michael Torrie wrote:
> I do recommend you at least take a look at Django. It may be overkill
> for your needs. It does contain a templating engine,
Last time I tried, the template-engine of Django did not work on its
own. If you need Django-like templates without Django, you can use Jinja.
And if you need a real sandbox (so that you can use untrusted templates),
I would recommend Jinja.
Roland
More information about the Python-list
mailing list