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.

Comments

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:

http://www.entrian.com/PyMeld/

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

Drawing Sierpinski's Triangle in Minecraft Using Python

In his keynote at PyCon, Eben Upton, the Executive Director of the Rasberry Pi Foundation, mentioned that not only has Minecraft been ported to the Rasberry Pi, but you can even control it with Python . Since four of my kids are avid Minecraft fans, I figured this might be a good time to teach them to program using Python. So I started yesterday with the goal of programming something cool for Minecraft and then showing it off at the San Francisco Python Meetup in the evening. The first problem that I faced was that I didn't have a Rasberry Pi. You can't hack Minecraft by just installing the Minecraft client. Speaking of which, I didn't have the Minecraft client installed either ;) My kids always play it on their Nexus 7s. I found an open source Minecraft server called Bukkit that "provides the means to extend the popular Minecraft multiplayer server." Then I found a plugin called RaspberryJuice that implements a subset of the Minecraft Pi modding API for B

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

Creating Windows 10 Boot Media for a Lenovo Thinkpad T410 Using Only a Mac and a Linux Machine

TL;DR: Giovanni and I struggled trying to get Windows 10 installed on the Lenovo Thinkpad T410. We struggled a lot trying to create the installation media because we only had a Mac and a Linux machine to work with. Everytime we tried to boot the USB thumb drive, it just showed us a blinking cursor. At the end, we finally realized that Windows 10 wasn't supported on this laptop :-/ I've heard that it took Thomas Edison 100 tries to figure out the right material to use as a lightbulb filament. Well, I'm no Thomas Edison, but I thought it might be noteworthy to document our attempts at getting it to boot off a USB thumb drive: Download the ISO. Attempt 1: Use Etcher. Etcher says it doesn't work for Windows. Attempt 2: Use Boot Camp Assistant. It doesn't have that feature anymore. Attempt 3: Use Disk Utility on a Mac. Erase a USB thumb drive: Format: ExFAT Scheme: GUID Partition Map Mount the ISO. Copy everything from