W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
此工具的目的是解碼傳入的請(qǐng)求參數(shù)。
此工具使用以下參數(shù) -
名稱(chēng) | 默認(rèn) | 描述 |
---|---|---|
encoding | None | 它查找內(nèi)容類(lè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(), '/')
上面的代碼從用戶(hù)獲取一個(gè)字符串,它將用戶(hù)重定向到“hello.html”頁(yè)面,在該頁(yè)面中,它將顯示為具有給定名稱(chēng)的“Hello”。
上述代碼的輸出如下 -
hello.html
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: