下面是一個簡單的示例,顯示訪問存儲對象中的值的各種方式都可以訪問。
基本上存儲對象可以被認爲是一個奇特的字典。它允許您像字典一樣訪問值,但也可以將值作爲屬性來訪問。
例外情況是變量名稱中有空格時,如「需要域」。在這種情況下,您需要使用字典符號進行訪問。
而且,這裏是存儲類的實現的鏈接(主外賣是,它是字典的一個子類):https://github.com/webpy/webpy/blob/master/web/utils.py#L52
示例使用的訪問屬性:
print response['Domain required']
print response['minutes needed']
print response.Submit
例使用循環(就像一個字典):
for k, v in cgi_fields.items():
print k, v
例web.py類:
class SomePage(object):
def GET(self):
web.header("Content-Type", "text/html")
return """
<html><body>
<form method="POST">
<input type="input" name="Domain required" />
<input type="input" name="example_field" />
<input type="input" name="example_field_2" />
<input type="submit" name="submit"/>
</form>
</body></html>
"""
def POST(self):
cgi_fields = web.input()
return cgi_fields['Domain required'], cgi_fields.example_field, cgi_fields.get('example_field_2')
請將您的程序減少到能夠再現問題的最小完整測試用例,並將該程序複製粘貼到您的問題中。見http://stackoverflow.com/help/mcve – 2014-10-17 16:17:52
這不是一個問題搶,這是表單輸出,輸出不是問題,我只是想分析它的變量。 – 2014-10-17 16:21:05
沒錯,但要查看您錯過的信息有助於瞭解您已經瞭解的內容。這是通過讓你提供一個正確運行的程序,直到你的困惑開始。 – 2014-10-17 16:26:28