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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -