You can convert every row to string in code using for
-loop, f-string
and join()
data = [
{'cins': 'kadin', 'gun': 'carsambra', 'id': '1', 'kat': 'cantra', 'sehir': 'izmir', 'tarz': '7', 'yas': '22'},
{'cins': 'kadin', 'gun': 'pazartesi', 'id': '1', 'kat': 'cantra', 'sehir': 'ankara', 'tarz': '5', 'yas': '18'},
]
new_data = []
for row in data:
text = ', '.join(f'{key}:{val}' for key, val in row.items())
new_data.append(text)
print(text)
Result
cins:kadin, gun:carsambra, id:1, kat:cantra, sehir:izmir, tarz:7, yas:22
cins:kadin, gun:pazartesi, id:1, kat:cantra, sehir:ankara, tarz:5, yas:18
and now you can send new data
to template.
Or you may try to do the same in template
using also for
-loop, row.items()
with key,val
and also loo.last
to skip ,
after last item
from flask import Flask, render_template_string
app = Flask(__name__)
@app.route('/')
def inder():
data = [
{'cins': 'kadin', 'gun': 'carsambra', 'id': '1', 'kat': 'cantra', 'sehir': 'izmir', 'tarz': '7', 'yas': '22'},
{'cins': 'kadin', 'gun': 'pazartesi', 'id': '1', 'kat': 'cantra', 'sehir': 'ankara', 'tarz': '5', 'yas': '18'},
]
return render_template_string("""
{% for row in data %}
<ul class="list-group">
<li class="list-group-item">
<h4>{% for key, val in row.items() %}{{key}}:{{val}}{{ ", " if not loop.last }}{% endfor %}</h4>
</li>
</ul>
{% endfor %}
""", data=data)
app.run(debug=True)