Why does wheezy.template try to render comment-ed out HTML and raise errors

Issue #22 new
Anonymous created an issue

I am learning wheezy.template from docs and after reading http://wheezytemplate.readthedocs.io/en/latest/userguide.html#filters I wrote the following code:

@require(user, items)

<header>Welcome ji, @user.age!s old @user.name</header>

@if items:
    @for count, i in enumerate(items):
        <li>@i.name: $ @i.price!s >> entry number @count!s</li>
        <li>@i.name: $ @i.price!s >> entry number @str(count+0.5)</li>
        <!-- <li>@i.name: $ @i.price!s - entry number @str(@count)</li> this mistake is intentional because comments should be ignored, right?-->
    No items found.

supply some dummy data and see that line number 10 of the template code, which contains intentional mistake but is also commented out, raises scary errors.

This is bad, commenting is important and if this happens no one will be able to write good code.

P.S. My python generated data looks like:

from collections import namedtuple

a_user = namedtuple("a_user", ["name", "age"])
item = namedtuple("item", ["name", "price"])

user = a_user("roger", 19)
items = \
[ item("doll", 11.6)
, item("cars", 99.4)
, item("desk", 0.01)

Comments (4)

  1. Satish Chandra Prasad

    Can we enforce a file extension for wheezy.template's template files (".wzt" sounds cool)?


    • explicit is better than implicit, PEP 20
    • wheezy.template is so powerful that template files are "python code with html-ish strings" and not "html page having some python variables". Hence, it deserves a file format of its own
    • developers, new or existing, will benefit from just looking at a different file extension -- it alerts them in their minds to change context. For example, for any useful purpose you template file should start with @require(...) which is not the norm when writing html
    • a dedicated extension will make it easy for code editors and IDEs to do syntax highlighting and other magic that they do -- this is essential for serious use of your library rather than toy projects
    • we are abusing the HTML standard if we do not respect W3C's guidelines (that everything inside <!-- and --> should be ignored), so calling a wheezy.template template file htm/html is technically incorrect
    • it is a convention across programming languages that while doing imports (or its equivalent engine.get_template(...)) we do not mention the extension; consider from functools import * or import {Component} from 'angular2/core'; then why should I do engine.get_template("index.htm")? engine.get_template("index") looks better and feels consistent (which will improve number of people adopting wheezy.template).

    I have already sent a pull request fee6dc8 to you regarding this. If you like my suggestion please test it, and if it works merge it into master.

  2. Log in to comment