Python web frameworks: HTML server-side templates and duplication of code -
i'm experimenting python web frameworks , html templates. concept seems restricted, compared generating entire html code on fly. instance, generate combo box, found following django templating example:
<select id="{{ item.name }}" name="{{ item.name }}"> {% choice in item.choices %} {% ifequal item.value choice %} <option value="{{ choice }}" selected>{{ choice }}</a> {% else %} <option value="{{ choice }}">{{ choice }}</a> {% endifequal %} {% endfor %} </select>
the ifequal statement duplicates entire code add "selected" attribute selected option. seems me becomes burden in html tags several attributes , few attributes exist or not depending on condition. above snippet bad usage of templating? there better way implement combo box using it?
it can written in single line in way.
<option value="{{ choice }}" {% ifequal item.value choice %}selected="selected"{% endifequal %}>{{ choice }}</option>
Comments
Post a Comment