469,354 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

templating system

Hi,

I am looking for fast, simple templating system that will allow me to
do the following:
- embed Python code (or some templating code) in the template
- generate text output (not only XML/HTML)

I don't need a framework (already have it), but just simple
templating. The syntax I had in mind is something like that:

# in Python module
def some_view():
# some code goes here...
records = get_some_data()
req = get_request_class()
return template('some_template.tmpl', **locals()).render()

# in some_template.tmpl:

<ul>
<%for record in records%>
<li><a href="<%=record.id%>"><%=record.title%></a></li>
<%end for%>
</ul>

From what I saw Cheetah seems to be the only one that can do it. I was

hoping there might be alternatives that I've missed :)
Thanks!

--
Ksenia
Jul 18 '05 #1
7 1136
Ksenia Marasanova wrote:
I am looking for fast, simple templating system that will allow me to
do the following:
- embed Python code (or some templating code) in the template
- generate text output (not only XML/HTML)

I don't need a framework (already have it), but just simple
templating. The syntax I had in mind is something like that:

# in Python module
def some_view():
# some code goes here...
records = get_some_data()
req = get_request_class()
return template('some_template.tmpl', **locals()).render()

# in some_template.tmpl:

<ul>
<%for record in records%>
<li><a href="<%=record.id%>"><%=record.title%></a></li>
<%end for%>
</ul>

From what I saw Cheetah seems to be the only one that can do it. I was

hoping there might be alternatives that I've missed :)
Thanks!


EmPy will also do this quite handily:

http://www.alcyone.com/software/empy/

In EmPy, your template would look something like this::

<ul>
@[for record in records]@
<li><a href="@record.id">@record.title</a></li>
@[end for]@
</ul>

Batch expanding the template would look like something as simple as
(substituting in your example)::

...
return em.expand(open(templateFilename).read(), **locals())

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
There's this perfect girl / Someone no one can see
-- Lamya
Jul 18 '05 #2
On Sun, 10 Apr 2005 17:55:06 +0200, Ksenia Marasanova
<ks***************@gmail.com> wrote:
Hi,

I am looking for fast, simple templating system that will allow me to
do the following:
- embed Python code (or some templating code) in the template
- generate text output (not only XML/HTML)

I don't need a framework (already have it), but just simple
templating. The syntax I had in mind is something like that:

# in Python module
def some_view():
# some code goes here...
records = get_some_data()
req = get_request_class()
return template('some_template.tmpl', **locals()).render()

# in some_template.tmpl:

<ul>
<%for record in records%>
<li><a href="<%=record.id%>"><%=record.title%></a></li>
<%end for%>
</ul>

From what I saw Cheetah seems to be the only one that can do it. I was

hoping there might be alternatives that I've missed :)
Thanks!


I use Cheetah along with publish.py by Chris Gonnerman. Cheetah
constructs web pages using .html templates and a python script, (which
is why I like it). Publish.py gives me fast one click publishing to
the web server, adding or removing files from the server to match my
local publish directory.

Looks like Chris also has a templating program here as well. I
haven't checked it out yet, so can't tell you about it.

http://newcenturycomputers.net/projects/webpub.html

Cheers,
Ron

Jul 18 '05 #3
> In EmPy, your template would look something like this::

<ul>
@[for record in records]@
<li><a href="@record.id">@record.title</a></li>
@[end for]@
</ul>

Batch expanding the template would look like something as simple as
(substituting in your example)::

...
return em.expand(open(templateFilename).read(), **locals())


Thanks!

I've read "Known issues and caveats" on the website:

"""
EmPy was primarily intended for static processing of documents,
rather than dynamic use, and hence speed of processing was not the
primary consideration in its design.
"""

Have you noticed any speed problems with EmPy?

--
Ksenia
Jul 18 '05 #4
Ksenia Marasanova wrote:
Thanks!

I've read "Known issues and caveats" on the website:

"""
EmPy was primarily intended for static processing of documents,
rather than dynamic use, and hence speed of processing was not the
primary consideration in its design.
"""

Have you noticed any speed problems with EmPy?


In the interests of full disclosure, I'm the author of EmPy.

All I meant by that note was that EmPy was not primarily designed for
blazing speed; that is, it could easily be made much more efficient in a
lot of ways. I've never had a need to do so, so it's always been low
priority. I've certainly never heard of any complaints of EmPy's speed
(or lack therefore) as being a problem in the field. Unless you huge
realtime demands, I doubt EmPy's speed would be a major impediment. (Of
course, if you find that it is, please tell me!)

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
A wise man never loses anything if he have himself.
-- Montaigne
Jul 18 '05 #5
> In the interests of full disclosure, I'm the author of EmPy.
Cool :)
All I meant by that note was that EmPy was not primarily designed for
blazing speed; that is, it could easily be made much more efficient in a
lot of ways. I've never had a need to do so, so it's always been low
priority. I've certainly never heard of any complaints of EmPy's speed
(or lack therefore) as being a problem in the field. Unless you huge
realtime demands, I doubt EmPy's speed would be a major impediment. (Of
course, if you find that it is, please tell me!)


No huge demands, just simple templating for a database-driven website.
I'll give EmPy a try, thank you.

--
Ksenia
Jul 18 '05 #6
>>>>> "Erik" == Erik Max Francis <ma*@alcyone.com> writes:

Erik> All I meant by that note was that EmPy was not primarily
Erik> designed for blazing speed; that is, it could easily be made
Erik> much more efficient in a lot of ways. I've never had a need

It would be interesting to see benchmarks comparing different
templating system. I suppose a web templating system like PSP (of
mod_python) would be optimized for speed.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #7
Ksenia Marasanova <ks***************@gmail.com> wrote in message news:<ma**************************************@pyt hon.org>...
Hi,

I am looking for fast, simple templating system that will allow me to
do the following:
- embed Python code (or some templating code) in the template
- generate text output (not only XML/HTML)

I don't need a framework (already have it), but just simple
templating. The syntax I had in mind is something like that:
...


Have you tried cherrytemplate?. It is designed for using with
cherrypy, but it can be easily used alone.

http://cherrytemplate.python-hosting.com/

--
David.
Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Bruce | last post: by
5 posts views Thread by Roger Jack | last post: by
31 posts views Thread by Leif K-Brooks | last post: by
1 post views Thread by Chris Ashley | last post: by
18 posts views Thread by pkassianidis | last post: by
reply views Thread by Chris Withers | last post: by
10 posts views Thread by Terrence Brannon | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.