##language:zh #pragma section-numbers off ##含有章节索引导航的 ZPyUG 文章通用模板 <> ## 默许导航,请保留 <> = Karrigell默认输出-中文编码 = {{{ LoYwEnG reply-to python-cn@googlegroups.com to python-cn@googlegroups.com date Tue, Aug 5, 2008 at 16:25 }}} subject [CPyUG:61497] [[http://groups.google.com/group/python-cn/browse_thread/thread/0b4024809918e1cf/146ca8ce51e8a5f7#146ca8ce51e8a5f7|Re: Karrigell的乱码问题]] ##startInc == 问题 == 这是lovelypython中CDay2里面的一段代码(部分): # -*- coding: utf-8 -*- def index(**args): p... {{{ # -*- coding: utf-8 -*- def index(**args): p = KQF('fm_cdwalk','POST',"index","CD Walk") p.addHtmNode('text',"keywd","文件名",{'size':20,'maxlength':50}) p.addGroup(["submit","btn_submit","Walk it!","btn"]) p.display() }}} * 当我用firefox^(Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071719 Firefox/3.0.1)^浏览时,上面的“文件名”显示的是乱码。 * 看了一下character encoing,firefox使用的是Western(ISO-8859-1),自己手动改成UTF-8后就成常了,但每刷新一次又是乱码即 firefox又再次选择了Western(ISO-8859-1)。 {{{ Ubuntu8.04 Python 2.5.2 }}} == 解决 == 自己摸索出来的,很有成就感,虽然不知道原因,但能成就好。正想想写个小结,却发现给Zoom. Quiet先写了。 不过我也要写写啦。。 文件KarrigellRequestHandler.py里面有个函数: {{{#!python def content_type(): "return content type for html texts" if not k_config.output_encoding: ct="text/html" else: ct="text/html; charset="+k_encoding_charsets.encoding2python_map.get( k_config.output_encoding, k_config.output_encoding) #encoding2mime_map return ct }}} 代码中的`k_encoding_charsets.encoding2python_map`原来是`k_encoding_charsets.encoding2mime_map`。因为我把k_config.outputEncoding(在k_config中改)改成"utf_8" ,但却发现`encoding2mime_map`中居然没有utf-8,而`encoding2python_map`有,所以就这么改过来了。 * 结果这么胡乱一改,居然可以了。 * 郁闷!Zoom.Quiet改的是Karrigell.ini。再改上面那些之前,conf下面有关encoding的都一个个改了试过了,都不行。看来是RP问题了。 == 最解决 == 2008/8/5 junyi sun :: * `RESPONSE['Content-Type'] = "text/html; charset=utf-8"` ##endInc ---- '''反馈'''