Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2008-08-05 09:38:37
Size: 2577
Editor: ZoomQuiet
Comment:
Revision 4 as of 2009-10-16 08:36:55
Size: 2583
Editor: limodou
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
= Karrigell中文编码 = = Karrigell默认输出-中文编码 =
Line 61: Line 61:
== 最解决 ==
 2008/8/5 junyi sun <[email protected]>::
  * `RESPONSE['Content-Type'] = "text/html; charset=utf-8"`
Line 66: Line 70:

创建 by -- ZoomQuiet [[[DateTime(2008-08-05T09:38:37Z)]]]
||<^>[[PageComment2]]||<^>[:/PageCommentData:PageCommentData]''||

TableOfContents

Include(ZPyUGnav)

Karrigell默认输出-中文编码

LoYwEnG <[email protected]>
reply-to        [email protected]
to      [email protected]
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的乱码问题]

问题

这是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里面有个函数:

   1 def content_type():
   2    "return content type for html texts"
   3    if not k_config.output_encoding:
   4        ct="text/html"
   5    else:
   6        ct="text/html; charset="+k_encoding_charsets.encoding2python_map.get(  
   7            k_config.output_encoding, k_config.output_encoding)
   8        #encoding2mime_map
   9    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 <[email protected]>
  • RESPONSE['Content-Type'] = "text/html; charset=utf-8"


反馈

MiscItems/2008-08-05 (last edited 2009-12-25 07:09:01 by localhost)