templating system

K

Ksenia Marasanova

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%>
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!
 
E

Erik Max Francis

Ksenia said:
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%>

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())
 
R

Ron_Adam

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%>

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
 
K

Ksenia Marasanova

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?
 
E

Erik Max Francis

Ksenia said:
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!)
 
K

Ksenia Marasanova

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.
 
V

Ville Vainio

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.
 
D

David Asorey ?lvarez

Ksenia Marasanova said:
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/
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top