'Correctly storing the list of items in db and then printing them item by item using jinja, flask and postgresql
Newbie here. I have recently started learning coding and trying to build a webapp from scratch using Flask, Jinja and PostgreSQL.
I am using a multi-select input to store a list of strengths in a field that I want to later print item by item.
Strengths = ['Communication','Teamwork']
Here is what I have done: init.py
class Note(db.Model):
id = db.Column(db.Integer, primary_key=True)
strengths = db.Column(db.String(10000))
form.html
<select
class="form-select"
id="strengths"
name="strengths"
multiple
data-allow-clear="true"
data-suggestions-threshold="0"
data-show-all-suggestions="true"
>
<option disabled hidden value="">Choose a skill to endorse...</option>
{% for skill in skills %}
<option value="{{skill.label}}">{{skill.label}}</option>
{% endfor %}
</select>
views.py
strengths = request.form.getlist('strengths')
print(strengths)
new_note = Note(strengths=strengths)
The above print statement works fine and shows the outpur as expected ['Communication','Teamwork']
However, when I try to print this in jinja using {{Strengths}}, I see this as the output {Communication,Teamwork}
Checking the postgreSQL db, I see that the list is stored as printed by jinja {Communication,Teamwork}.
How can I make sure I can store the list in a way that I can print the first strength by using {{strengths[0]}}?
TIA
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
