V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ccmao755
V2EX  ›  Python

关于输出中文 unicode

  •  
  •   ccmao755 · 2015-08-14 13:59:38 +08:00 · 2153 次点击
    这是一个创建于 3184 天前的主题,其中的信息可能已经有所发展或是发生改变。

    flask + pymmsql
    render_template 返回的是([‘中国’,123],[‘深圳’,234]) 这样2个list在一个tuple之中。 那么返回个template的时候(显示明细),我用a[0][0]本来想输出 中国,但是输出的是unicode字符。

    我在jinja2 用decode(utf-8)以及render_template也用decode('utf-8')都是显示的16进制的unicode显示,在console里可以 用print a[0][0] 显示正确的中文。

    请问大家都是如何处理的呢?谢谢! pymssql连接已用utf8连接,py文件也做了utf8的声明。

    3 条回复
    clino
        1
    clino  
       2015-08-14 14:06:33 +08:00
    感觉你发错版了
    ccmao755
        2
    ccmao755  
    OP
       2015-08-14 14:09:58 +08:00
    哦,是啊,我重新发到flask去了,谢谢提醒
    Livid
        3
    Livid  
    MOD
       2015-08-17 09:37:48 +08:00
    没有问题。这个帖子也为你移动到 /go/python 了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   820 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:42 · PVG 06:42 · LAX 15:42 · JFK 18:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.