+ -
当前位置:首页 → 问答吧 → webpy 如何返回中文?

webpy 如何返回中文?

时间:2011-10-20

来源:互联网

服务器端用的是webpy,因为用了 ajax,所以服务器返回时直接 “return 结果”, 但是因为搞不清楚python的编码,无论怎么,服务器都返回 '\xe6\x95\xb0\xe6\x8d\xae\xe5\xba' 这样的字符串,请问如何返回中文字符串?

作者: zhangweiwindow   发布时间: 2011-10-20

补充一下。以下是代码:
Python code

def GET(self):
        '''
        从数据库中获取权限内容并添加到web页面的选择列表中
        '''
        operations = self.db.connection.select('sys_operation_dim')

        if mode == "RIA":
            result = {
                "total":"",
                "lines" : []
            }

            total = 0
            web.header("Content-Type","text/plain; charset=utf-8")
            for operation in operations:
                total += 1
                result["lines"].append({"index":str(total), "operationCode": operation['operation_code'], "operationName":operation['operation_name']})
            result["total"] = str(total)
            print result["lines"][0]["operationName"]
            return result



在倒数第二行中,用print在控制台中输入是中文,但是 return 后就成了楼上所说的内容了。

各位路过大侠请伸出援手。

作者: zhangweiwindow   发布时间: 2011-10-20