I have the below function which returns a list
JavaScript
x
10
10
1
def get_entered_datalist(firstname, lastname):
2
if firstname and lastname:
3
curr = db.session.execute(entered_data, {'firstname': firstname, 'lastname': lastname})
4
list_name = list() #this is a list contstructor statement so have () brackets, usually when declaring list we use [] brackets
5
for name in curr:
6
list_name.append(name)
7
return list_name
8
else:
9
return False
10
It is being called this way
JavaScript
1
2
1
entered_names = get_entered_datalist(session['v_firstname'], session['v_lastname'])
2
and passed to the html file this way
JavaScript
1
2
1
return render_template('monthlybudget.html', title='Enter Monthly Budget Data', form=form, entereddata=entered_names)
2
The display code in HTML file is as below
JavaScript
1
8
1
{% if entereddata %}
2
{% for x in entereddata %}
3
<p>{{ x }} </p>
4
{% endfor %}
5
{% else %}
6
<p>No data found</p>
7
{% endif %}
8
but it is being displayed with round brackets and quote marks as below
The query getting the values from database is as below
JavaScript
1
4
1
select concat([First Name], ' ', [Last Name] ) as name from [dbo].[EAMonthlyBudget]
2
where [Report to First Name]= :firstname and [Report to Last Name] = :lastname
3
and [budget month] = datename(month,getdate()) and [budget year] = year(getdate());
4
I added a print statement in my python code to check what gets returned by the function and that is as below (shows with the brackets and quote marks)
JavaScript
1
4
1
[12/Aug/2022 15:29:44] "GET /static/images/nu_logo2.png HTTP/1.1" 304 -
2
[('Janak Shah',), ('Julie Wang',)]
3
-
4
How do I display the data without the brackets and quote marks?
Advertisement
Answer
Your curr variable contains tuples. try this code:
JavaScript
1
3
1
for name in curr:
2
list_name.append(name[0])
3
I think you need to check of index out for range error.
I hope this helps.