I have sorted list of cities called sorted_cities=[Atlanta, Berlin, Bern, Calgary] that I am sorting in alpha order and would like to display on the web with ability to click on the city to get detailed information as well as select city to get notifications via e-mail. I want the output on the web look as follows:
A
Atlanta
B
Berlin
Bern
C
Calgary
I have the following code in Python 3.x that works fine:
sorted_names=sorted(names,key=str.lower)
print(sorted_names)
for letter, words in groupby(sorted_names,key=itemgetter(0)):
print(letter)
for word in words:
print(word)
I created this code in Jinja2 but it does not work:
{% block content %}
<div>
<form action="cities" method="post">
{% for group in sorted_names|groupby("letter") %}
<li><b>{{ group.grouper }} </b></li>
{% for word in group.list %}
<input type="checkbox" name="city" value="{{ word }}"> <a href="/{{ word }}">{{ word }}</a><br>
{% endfor %}
{% endfor %}
<input type="submit" value="Submit">
</form>
</div>
{% endblock %}