473,471 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1241
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bruce | last post by:
Which of the popular templating systems (e.g. PHLib, FastTemplate, Smarty) allow you to setup conditions in your templates, for example: <-- IF Variable=value --> this HTML <-- ELSEIF...
5
by: Roger Jack | last post by:
I have just finished reading Code Generation In Action which uses Ruby for code generation. I would like to use Python instead. Is Cheetah the best tool to use for templating source code files and...
31
by: Leif K-Brooks | last post by:
I'm planning to start on a fairly large web application, most likely using mod_python. I recently wrote a fairly small (but real-world useful) web app with it, and all of those req.write()s made...
3
by: Chris Stiles | last post by:
Hi -- Does anyone have any recommendations for simple web templating systems for python that also allow execution of python code within the the templates themselves ? So far I'm using...
1
by: Chris Ashley | last post by:
I have been looking into templating systems these past few days, but nothing seems to suit my purpose. I want to achieve complete separation of code and design in a templating system, so a designer...
18
by: pkassianidis | last post by:
Hello everybody, I am in the process of writing my very first web application in Python, and I need a way to generate dynamic HTML pages with data from a database. I have to say I am...
0
by: Chris Withers | last post by:
Hi All, I'm proud to announce that after almost a year's development, the first public release of Twiddler is available! Twiddler is a simple but flexible templating system for dynamically...
7
by: Paul | last post by:
I have been coding apps with PHP for several years. But I am getting more involved in larger and more complicated PHP applications and want to use best practices. I use Eclipse's PHP IDE. I...
10
by: Terrence Brannon | last post by:
Hello, The most common way of dynamically producing HTML is via template engines like genshi, cheetah, makotemplates, etc. These engines are 'inline' --- they intersperse programming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.