Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python将列表传递到表单中并作为列表检索_Python_Cgi - Fatal编程技术网

Python将列表传递到表单中并作为列表检索

Python将列表传递到表单中并作为列表检索,python,cgi,Python,Cgi,在python(cgi)中,通过表单传递列表的最佳方式是什么 ListStr=['State1','State2','State3'] TrVListStr='##'。连接(ListStr) 打印“” """ 提交后,我应该有一个列表,因为它是在提交前 我可以使用split(基于##规则)表单['state\u carry].value再次获取该值。但我认为这不是一个好办法 有没有办法通过表单传递Python列表并在以后检索它们 谢谢。您可以使用python。文档描述了一个字段名有多个值的情

在python(cgi)中,通过表单传递列表的最佳方式是什么

ListStr=['State1','State2','State3']
TrVListStr='##'。连接(ListStr)
打印“”

"""
提交后,我应该有一个列表,因为它是在提交前

我可以使用split(基于##规则)表单['state\u carry].value再次获取该值。但我认为这不是一个好办法

有没有办法通过表单传递Python列表并在以后检索它们

谢谢。

您可以使用python。文档描述了一个字段名有多个值的情况

基本思想是,在html表单中可以有多个同名字段,每个字段的值都是列表中的一个值。然后,可以使用该方法以列表的形式检索所有值。例如:

print "<form method=\"post\">"

for s in ListStr:
    print "<input type=hidden name=\"state_carry\" value=\"" + s + "\"><br />"

print "<input type=\"submit\" value=\"Submit\" />"
print "</form>"
您可以使用python。文档描述了一个字段名有多个值的情况

基本思想是,在html表单中可以有多个同名字段,每个字段的值都是列表中的一个值。然后,可以使用该方法以列表的形式检索所有值。例如:

print "<form method=\"post\">"

for s in ListStr:
    print "<input type=hidden name=\"state_carry\" value=\"" + s + "\"><br />"

print "<input type=\"submit\" value=\"Submit\" />"
print "</form>"
在python中,我会这样做

###In the form page.
import cgi

#Convert list of values to string before passing them to action page.
ListStr=','.join(['State1', 'State2', 'State3'])

print "<input type=hidden name=\"state_carry\" value=\""+ListStr+"\"><br />"

###In the action page
import cgi

#Return the string passed in the user interaction page and transform it back to a list.
ListStr=cgi.FieldStorage().getvalue('state_carry').split(',')
表单页面中的
####。
导入cgi
#将值列表转换为字符串,然后再将其传递到操作页面。
ListStr=','.join(['State1','State2','State3'])
打印“
” ###在操作页面中 导入cgi #返回在用户交互页面中传递的字符串,并将其转换回列表。 ListStr=cgi.FieldStorage().getvalue('state_carry').split(','))
在python中我会这样做

###In the form page.
import cgi

#Convert list of values to string before passing them to action page.
ListStr=','.join(['State1', 'State2', 'State3'])

print "<input type=hidden name=\"state_carry\" value=\""+ListStr+"\"><br />"

###In the action page
import cgi

#Return the string passed in the user interaction page and transform it back to a list.
ListStr=cgi.FieldStorage().getvalue('state_carry').split(',')
表单页面中的
####。
导入cgi
#将值列表转换为字符串,然后再将其传递到操作页面。
ListStr=','.join(['State1','State2','State3'])
打印“
” ###在操作页面中 导入cgi #返回在用户交互页面中传递的字符串,并将其转换回列表。 ListStr=cgi.FieldStorage().getvalue('state_carry').split(','))
我发现在1时特别通过列表是很乏味的。清单是大2。多次连续传球。所以我发现最好是本地存储在一个文件中。我发现传递列表特别是当1。清单是大2。多次连续传球。因此,我发现最好在本地存储一个文件。