python3版中使用web.notfound一直乱码,察看原代码中发现Content-Type设置不正确
class _NotFound(HTTPError):
"""`404 Not Found` error."""
message = "not found"
def __init__(self, message=None):
status = '404 Not Found'
headers = {'Content-Type': 'text/html;'}
HTTPError.__init__(self, status, headers, message or self.message)
headers应该设置为{'Content-Type': 'text/html; charset=utf-8'}就解决问题了,同理很多有中文乱码问题地方都可以检查下
另外代码中有return中文地方可以在前面加一行web.header('Content-Type', 'text/html; charset=utf-8')
def POST(self):
web.header('Content-Type', 'text/html; charset=utf-8')
return "中文不乱码了"