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

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 Bukkit s…

Apple: iPad and Emacs

Someone asked my boss's buddy Art Medlar if he was going to buy an iPad. He said, "I figure as soon as it runs Emacs, that will be the sign to buy." I think he was just trying to be funny, but his statement is actually fairly profound.

It's well known that submitting iPhone and iPad applications for sale on Apple's store is a huge pain--even if they're free and open source. Apple is acting as a gatekeeper for what is and isn't allowed on your device. I heard that Apple would never allow a scripting language to be installed on your iPad because it would allow end users to run code that they hadn't verified. (I don't have a reference for this, but if you do, please post it below.) Emacs is mostly written in Emacs Lisp. Per Apple's policy, I don't think it'll ever be possible to run Emacs on the iPad.

Emacs was written by Richard Stallman, and it practically defines the Free Software movement (in a manner of speaking at least). Stal…

JavaScript: Porting from react-css-modules to babel-plugin-react-css-modules (with Less)

I recently found a bug in react-css-modules that prevented me from upgrading react-mobx which prevented us from upgrading to React 16. Then, I found out that react-css-modules is "no longer actively maintained". Hence, whether I wanted to or not, I was kind of forced into moving from react-css-modules to babel-plugin-react-css-modules. Doing the port is mostly straightforward. Once I switched libraries, the rest of the port was basically:
Get ESLint to pass now that react-css-modules is no longer available.Get babel-plugin-react-css-modules working with Less.Get my Karma tests to at least build.Get the Karma tests to pass.Test things thoroughly.Fight off merge conflicts from the rest of engineering every 10 minutes ;) There were a few things that resulted in difficult code changes. That's what the rest of this blog post is about. I don't think you can fix all of these things ahead of time. Just read through them and keep them in mind as you follow the approach above.…