CherryPy 解码工具

2023-12-31 21:57 更新

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

参数 (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

解码工具输出


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号