I'm trying to retrieve the database results to a webpage using Python 2.7(flask) but stuck with the unicode issues. Below is the code I'm using
def formval():
# --connection syntax here--
cursor = connection.cursor()
if request.method == 'POST':
x = request.form['weekno']
cursor.execute("SELECT Document FROM Backlog where custno=?",x)
result = cursor.fetchall()
return render_template('home.html',weekno=result)
home.html
{% for docno in weekno %}
<p>{{ docno }}</p>
{% endfor %}
Output : This gives me the output as below
u'sp234780'
u'sd257679'
---------
---------
But when I use return render_template('home.html',weekno=result[0]) I'm getting the output as just sp234780 but only the first row not the entire results.
I've gone through all the posts related to encoding and tried to use encode('utf-8'), sys.setdefaultsetting(utf-8) etc but no luck
Please suggest