0

I have the following code in index.html file and I am trying to sort the output A-Z.

Would it be possible by editing this code only?

{% for x in data.pairs %}
<option>{{ x }}</option>
{% endfor %}
benvc
  • 14,448
  • 4
  • 33
  • 54

2 Answers2

0

I think you can do this.

{% for x in data.paris.all|dictsort:"variable name" %} {{ x }} {% endfor %}

Please follow the below mentioned documentation for details. Select your desire django version.

https://docs.djangoproject.com/en/dev/ref/templates/builtins/#std:templatefilter-dictsort

0

{% for x in data.pairs|sort %} <option>{{ x }}</option> {% endfor %} This works perfectly