# -*- coding: utf-8 -*-
import os, datetime,sys,codecs,MySQLdb,math
db=MySQLdb.connect(...use_unicode=True,charset='utf8')
db.set_character_set('utf8')
cursor= db.cursor()
....
@route('/dealers')
def main_dealers():
cursor.execute('select * from dealer ')
data=cursor.fetchall();
return template('dealers', title= 'Dealers',names=data)
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<ul>
%for name in names:
<li>{{name[1]}}</li>
%end
</ul>
</body>
</html>
Собственно имею ошибку
UnicodeEncodeError: ‘ascii’ codec can't encode characters in position 0-7: ordinal not in range(128)
если сделать
def main_dealers():
cursor.execute('select * from dealer ')
data=cursor.fetchall();
hu=u'<html> <head> </head> <body> <ul>'
for line in data:
hu=hu+'<li>'+line[1]+'<li>'
hu=hu+'</ul> </body></html>'
# return template('dealers', title= 'Dealers',names=data)
return hu