Django template filter to create an list of items that join on commas and end on "and" -


I think I'm writing something that already exists.

Is Django's template filter a comma and a list of objects at places and before the previous one could be included in 'and'?

For example:

  a = ['foo',] b = ['The filter I'm looking for will display each list in the following ways:  

P>

will display a 'foo'. B will appear 'bar and falcon' c 'fu, bar and hawk Will display 'D' Fu, Bar, Falcon, and your Mom 'will show'.

Question 1: Is there anything that already does?


I tried to write it myself in two places:

My code:

Question 2 : It breaks on forloop.counter & amp; amp; Tc.author.all | Length. Please explain why these are not valid.

You can do this in your template:

 < Code> {% item in list} {% ifloop.first%} {% else%} {% ifloop.last%} and {% else%}, {% endif%} {% Endif%} {{item}} {% Endfor%}  


Line breaks have been added for clarity: Remove them to avoid unwanted spaces Output:

{% item in list} {% ifloop.first%} {% else%} {% ifloop.last%} and {% else%}, {% Endif%} {% endif% } {{Items}} {% endfor%}


edit: to make me change codes L Thanks to Eric Fortin, I was confused.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -