Skip to content

Instantly share code, notes, and snippets.

@RaidoS
Created April 10, 2017 14:54
Show Gist options
  • Save RaidoS/716dd7ecdf0caa08bd5978f7214cef67 to your computer and use it in GitHub Desktop.
Save RaidoS/716dd7ecdf0caa08bd5978f7214cef67 to your computer and use it in GitHub Desktop.
Django templates trick for comma separated lists, exclude "comming" last item
<!-- template.html -->
{% for item in items %}
<a href="{{item.slug}}">{{item.name}}</a>{% include "comma.html" %}
{% endfor %}
<!-- comma.html -->
{% if not forloop.last %}
{% ifequal forloop.revcounter 2 %} и {% else %}, {% endifequal %}
{% else %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment