Web development with Python 3.1

Diez B. Roggisch deets at nospam.web.de
Thu Oct 29 17:21:05 CET 2009

Dotan Cohen wrote:

>> Perhaps this might better answer your questions:
>> http://docs.djangoproject.com/en/dev/topics/templates/#id1
> Actually, that example just proves my point! Look at this "templating
> code":
> {% for entry in blog_entries %}
>     <h2>{{ entry.title }}</h2>
>     <p>{{ entry.body }}</p>
> {% endfor %}
> Why would I want to learn that when Python already has a real for
> loop? I know HTML, and I have a goal of learning Python for it's
> reusability (desktop apps, for instance). I don't want to learn some
> "templating language" that duplicates what Python already has built
> in!

The point is that using templates allows you to express your rendering-logic
in terms of the desired output language (HTML in this case).

This becomes even more apparent in genshi/KID, which use XML-namespaces
inside normal XHTML-documents to express their logic. And thus you can

 - use a decent XML/HTML-editor to work with them, syntax-hilighting and
everthing included.
 - communicate better with people who are only used to work with HTML
 - aren't a slave to Python's whitespace rules which are fine for Python,
but not for HTML.
 - validate the HTML and be sure you don't f*ck it up with forgotten

And the overall separation of rendering from programming is a *great* thing
for maintainability.


More information about the Python-list mailing list