I'm trying to take inputs from a stringfield in WTForms and iterate them to show up in an app.
The inputs seem to work just fine, separate words go into the db as separate words.
However, when I try to use jinja to display the inputs on an html page, it comes out as individual characters.
This is my code for the form, the route, and the html file.
class UserForm(FlaskForm):
fav_movies = StringField('Favorite Movies')
fav_games = StringField('Favorite Games')
if user.fav_movies:
fav_movie_list = [fm for fm in user.fav_movies]
else:
fav_movie_list = []
if user.fav_games:
fav_games_list = [yf for yf in user.fav_games]
else:
fav_games_list = []
{% if fav_movies %}
<p class="display-6"><strong>{{ user.name }}'s Favorite Movies</strong></p>
<ul class="list-group list-group-flush">
{% for fm in fav_movies %}
<li class="list-group-item">{{ fm }}</li>
{% endfor %}
</ul>
{% endif %}
{% if fav_games %}
<p class="display-6"><strong>{{ user.name }}'s Favorite Games</strong></p>
<ul class="list-group list-group-flush">
{% for fg in fav_games %}
<li class="list-group-item">{{ fg }}</li>
{% endfor %}
</ul>
{% endif %}
I was expecting something like:
Iron Man
Hulk
Dune
Instead I got
I
r
o
n
M
a
n
H
u
l
k
D
u
n
e
Separating the words with quote or commas just added those characters to the vertical list.