I am wondering if there is a style guide anywhere for writing Django
templates. Also, are there programs to automatically format your
templates...to indent block tags, for example? I know there are
autoformatters for HTML, but I am not aware of any tools that handle
Django tags. Also, it would be nice to have a command line tool that
detected unbalanced tags before rendering occurs, knowing, of course,
that that task is a little complicated due to conditionals.
Here is example code that I would wish to reformat:
{% load i18n %}
<div class="submit-row" {% if is_popup %}style="overflow: auto;"{%
endif %}>
{% if show_save %}<input type="submit" value="{% trans 'Save' %}"
class="default" name="_save" {{ onclick_attrib }}/>{% endif %}
{% if show_delete_link %}<p class="deletelink-box"><a
href="delete/" class="deletelink">{% trans "Delete" %}</a></p>{% endif
%}
{% if show_save_as_new %}<input type="submit" value="{% trans
'Save as new' %}" name="_saveasnew" {{ onclick_attrib }}/>{%endif%}
{% if show_save_and_add_another %}<input type="submit" value="{%
trans 'Save and add another' %}"
name="_addanother" {{ onclick_attrib }} />{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{%
trans 'Save and continue editing' %}"
name="_continue" {{ onclick_attrib }}/>{% endif %}
</div>
It seems like this would be more readable. The if statements get
indented, except where they are inside an HTML tag. Also the
statements inside the div get indented.
{% load i18n %}
<div class="submit-row" {% if is_popup %}style="overflow: auto;"{%
endif %}>
{% if show_save %}
<input type="submit" value="{% trans 'Save' %}"
class="default" name="_save" {{ onclick_attrib }}/>
{% endif %}
{% if show_delete_link %}
<p class="deletelink-box"><a href="delete/"
class="deletelink">{% trans "Delete" %}</a></p>
{% endif %}
{% if show_save_as_new %}
<input type="submit" value="{% trans 'Save as new' %}"
name="_saveasnew" {{ onclick_attrib }}/>
{%endif%}
{% if show_save_and_add_another %}
<input type="submit" value="{% trans 'Save and add
another' %}" name="_addanother" {{ onclick_attrib }} />
{% endif %}
{% if show_save_and_continue %}
<input type="submit" value="{% trans 'Save and continue
editing' %}" name="_continue" {{ onclick_attrib }}/>
{% endif %}
</div>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.