Skip to content

Django template coding convention

1337 edited this page Jun 4, 2012 · 3 revisions

tl;dr

  • Not available

Line Length

Strictly less than or equal to 80 characters, unless any of these applies:

  • it is impossible to break the line up to below 80 characters
  • it looks uglier than before you trim it down to 80 characters

Note that the Python coding convention dictates a line length of at most 79 characters, so it is advised that you follow the 79-character rule for HTML as well.

Django Tags

  • one space inside each side of the tags: {{ variable_name }}
  • no spaces between filters: {{ variable_name|striptags|escape }}
  • control operators (e.g. for, if) indent inside even if the resultant html file is incorrectly aligned, i.e.
<html>
{% if true %}
    <indent spaces="4" />
{% endif %}
  • All Django block tags must end with a named endblock tag: {% endblock blah %}
  • Django template extensions must contain all tags of their parents. If a tag is unused, put in a filler: {% block unused %}{% endblock unused %}

Tabs and spaces

  • no tab characters of any kind shall be found in our code.
  • no trailing spaces of any kind shall be found in our code.
  • indentation: 4 hard spaces.

Comments

HTML Comments must begin with <!-- (including the space) and end with --> (including the space).

  • Forbidden: <!----------------HYPHENATED-COMMENT-LINES--------------->
  • Forbidden: <!------->
  • Forbidden: <!--Comments without spaces after the opening hyphens-->

Django template comments are currently unrestricted.

Clone this wiki locally