codecamp

CherryPy 解码工具

此工具的目的是解码传入的请求参数。

参数 (Arguments)

此工具使用以下参数 -

名称默认描述
encodingNone它查找内容类型标头
Default_encoding"UTF-8"未提供或未找到时使用的默认编码。

例子 (Example)

让我们举一个例子来了解它是如何工作的 -

import cherrypy
from cherrypy import tools
class Root:
@cherrypy.expose
def index(self):
return """ 
<html>
   <head></head>
   <body>
      <form action = "hello.html" method = "post">
         <input type = "text" name = "name" value = "" />
         <input type = ”submit” name = "submit"/>
      </form>
   </body>
</html>
"""
@cherrypy.expose
@tools.decode(encoding='ISO-88510-1')
def hello(self, name):
return "Hello %s" % (name, )
if __name__ == '__main__':
cherrypy.quickstart(Root(), '/')

上面的代码从用户获取一个字符串,它将用户重定向到“hello.html”页面,在该页面中,它将显示为具有给定名称的“Hello”。

上述代码的输出如下 -

解码工具

hello.html
  • 1
  • 2

解码工具输出


CherryPy 缓存工具
CherryPy 文件系统
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

CherryPy 一个工作应用程序

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }