Why when django picks up data from Mysql, the data shown on the html is messy code -
here's views.py code
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys #import chardet reload(sys) sys.setdefaultencoding('utf8') django.shortcuts import render import mysqldb def myview(request): db = mysqldb.connect( host = 'localhost', port = 3306, user = 'root', passwd = '123', db = 'new_gkgw', ) cur = db.cursor() db.commit() aa = cur.execute("select * shici") bb = cur.fetchmany(aa) return render(request, 'dict/mytemplate.html', {"rows": bb})
here's template's code
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <ul> {% row in rows %} <li>{{ row }}</li> {% endfor %} </ul> </body> </html>
here's my.cnf
[mysqld] default-storage-engine = innodb character-set-server = utf8mb4 collation-server = utf8mb4_bin [client] default-character-set = utf8mb4 init_connect = 'set names utf8mb4'
and here messy code shown on html, it's messy.
(1l, '?', '1.?????????(???????)', '2.????????????(?)?????(?)?????????????', '3.????????(?)???????????????', none, none, none, none, none, none)
help me please....
Comments
Post a Comment