Skip to main content

Python: HTMLTemplate

Paul Abrams suggested to me the idea of having 100% pure HTML, and then using some DOM on the server side to splice chunks of HTML together. After talking about it for about two hours, I became excited about the idea, and I wondered if it would be pleasant in practice in contrast to, say, Cheetah. At the very least, it would be an interesting alternative.

It turns out that HTMLTemplate is one such system. I asked the Python web-sig about it, as well as a few other people. Tung Wai Yip said that he really liked HTMLTemplate. I figured my buddy, Donovan Preston, of Nevow fame would like it because he's a fan of getting away from the whole "big chunk of HTML in an amorphous string" idea. Ian Bicking had the following comment, which I feel was very perceptive:

If there's no code then it's not a presentation layer. It's an HTML layer, nothing more, just dumb data. Presentation requires logic.

Ksenia Marasanova, the newest member added to the Aquarium project, had the following comments based on real experience:

I used it quite a lot, and while it is fast, bugs free and simple to use, total separation of markup and code is IMHO contraproductive - every simple change mostly requires changing two files.

Since Ksenia's opinion is based on experience, it carries a lot of weight in my mind. Feel free to add your comments below.


jjinux said…
If Paul Abrams were here, instead of taking care of his newly born child, he might object to my statement that HTMLTemplate is similar to his idea. HTMLTemplate is based on doing callbacks based on various HTML tag attributes. In contrast, in Paul Abrams' idea, the template was completely inactive, and the server was responsible for pro-actively modifying the DOM. I think the various comments above still apply.
Paul Bissex said…
Belatedly coming across this post -- just wanted to mention PyMeld also:

I have to say, while I find these types of systems really fun to play with, for plain ol' web apps I haven't yet found a situation that really calls for them. I get a lot more mileage out of a good text-based tempating system (e.g. Django's) that supports template inheritance.
livingcosmos said…
not only that, but check out
Meld3 before passing judgement on Python approaches to separating HTML and Python code.
Anonymous said…
Saying that there is "no code" in simple template systems, such as Hamish Sanderson's HTMLtemplate, is misleading. My attraction to these minimalistic systems is related to my attraction to Python. They both "get out of your way". Embedded tag attributes, to be interpreted by the templating engine, are in fact pointers, since they are the names of, or parameters to, code objects which are applied to the associated tag / block. The fact that the raw templates are transparent to a browser's rendering engine is a very great advantage, which implies that a "web designer's" tool of choice (cough Dreamweaver cough) will also safely ignore the attribute:value pairs. When it comes to keeping a production pipeline running (design -> code -> test -> publish), including (especially!) round-tripping, when design / functionality is updated, simplicity is the name of the game!

Re. editing "at least two files", if the changes to those multiple files are simple, and comprehensible, it can still be much more effective than wrangling a single "intertwingled" template file which both designers and coders must "grok", or at least not break, during updates.
jjinux said…
I've been doing Web development for a long time, and I have always preferred a different work style.

I prefer designers to give me HTML templates, and then I integrate them into the system. Many designers don't even know how to create semantic HTML or organize CSS properly, so I often don't rely on them for anything other than design.

On the other hand, for more technical designers, I often help them setup a build environment so that they can edit templates running live using a normal text editor.

Personally, I refuse to allow anything from DreamWeaver into a real application.

Popular posts from this blog

Ubuntu 20.04 on a 2015 15" MacBook Pro

I decided to give Ubuntu 20.04 a try on my 2015 15" MacBook Pro. I didn't actually install it; I just live booted from a USB thumb drive which was enough to try out everything I wanted. In summary, it's not perfect, and issues with my camera would prevent me from switching, but given the right hardware, I think it's a really viable option. The first thing I wanted to try was what would happen if I plugged in a non-HiDPI screen given that my laptop has a HiDPI screen. Without sub-pixel scaling, whatever scale rate I picked for one screen would apply to the other. However, once I turned on sub-pixel scaling, I was able to pick different scale rates for the internal and external displays. That looked ok. I tried plugging in and unplugging multiple times, and it didn't crash. I doubt it'd work with my Thunderbolt display at work, but it worked fine for my HDMI displays at home. I even plugged it into my TV, and it stuck to the 100% scaling I picked for the othe

ERNOS: Erlang Networked Operating System

I've been reading Dreaming in Code lately, and I really like it. If you're not a dreamer, you may safely skip the rest of this post ;) In Chapter 10, "Engineers and Artists", Alan Kay, John Backus, and Jaron Lanier really got me thinking. I've also been thinking a lot about Minix 3 , Erlang , and the original Lisp machine . The ideas are beginning to synthesize into something cohesive--more than just the sum of their parts. Now, I'm sure that many of these ideas have already been envisioned within , LLVM , Microsoft's Singularity project, or in some other place that I haven't managed to discover or fully read, but I'm going to blog them anyway. Rather than wax philosophical, let me just dump out some ideas: Start with Minix 3. It's a new microkernel, and it's meant for real use, unlike the original Minix. "This new OS is extremely small, with the part that runs in kernel mode under 4000 lines of executable code.&quo

Haskell or Erlang?

I've coded in both Erlang and Haskell. Erlang is practical, efficient, and useful. It's got a wonderful niche in the distributed world, and it has some real success stories such as CouchDB and Haskell is elegant and beautiful. It's been successful in various programming language competitions. I have some experience in both, but I'm thinking it's time to really commit to learning one of them on a professional level. They both have good books out now, and it's probably time I read one of those books cover to cover. My question is which? Back in 2000, Perl had established a real niche for systems administration, CGI, and text processing. The syntax wasn't exactly beautiful (unless you're into that sort of thing), but it was popular and mature. Python hadn't really become popular, nor did it really have a strong niche (at least as far as I could see). I went with Python because of its elegance, but since then, I've coded both p