Web.py HelloWorld与中文乱码

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

一、安装web.py

sudo easy_install web.py

二、代码

# coding=utf-8
import web

urls=(
      '/','index'
)

class index:
    def GET(self):
        web.header('Content-Type','text/html;charset=UTF-8')
        return 'Hello Word!你好!'
    
if __name__=='__main__':
    app=web.application(urls,globals())
    app.run()

三、运行

~$ python index.py 8000
http://0.0.0.0:8000/
127.0.0.1:50398 - - [22/May/2016 11:23:07] "HTTP/1.1 GET /" - 200 OK

Web.py HelloWorld与中文乱码_第1张图片

 

加上:

        web.header('Content-Type','text/html;charset=UTF-8')

中文才能正常显示。

转载于:https://my.oschina.net/u/2245781/blog/679269

你可能感兴趣的:(Web.py HelloWorld与中文乱码)