Skip to content

Django template coding convention

1337 edited this page Jun 8, 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.

HTML Tags

  • Use tags for their semantics. Avoid divs except for layouts.
  • I (@1337) think using tables for tabular layouts are fine, while others avoid the table tag like the plague, sometimes even for setting tables. If you want to pass your next code review, consider avoiding it, too.

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 with a blank line in between:

{% 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