此工具的目的是解碼傳入的請(qǐng)求參數(shù)。
此工具使用以下參數(shù) -
名稱 | 默認(rèn) | 描述 |
---|---|---|
encoding | None | 它查找內(nèi)容類型標(biāo)頭 |
Default_encoding | "UTF-8" | 未提供或未找到時(shí)使用的默認(rèn)編碼。 |
讓我們舉一個(gè)例子來(lái)了解它是如何工作的 -
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(), '/')
上面的代碼從用戶獲取一個(gè)字符串,它將用戶重定向到“hello.html”頁(yè)面,在該頁(yè)面中,它將顯示為具有給定名稱的“Hello”。
上述代碼的輸出如下 -
hello.html
更多建議: