【发布时间】:2013-10-15 18:35:12
【问题描述】:
我有一个非常简单的金字塔/pylons web 应用程序,只有一个页面(主页)在 home.pt 模板上详细说明,如下所示:
<form action="/" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<fieldset>
<div>
<input type="radio" name="myradio" value="left" id="choice1"/>
<label for="choice1">Choice1</label>
<input type="radio" name="myradio" value="right" id="choice2"/>
<label for="choice2">Choice2</label></div>
<p>Form Controls</p>
<input type="submit" name='form.submitted' value="Submit"/>
<input type="reset" value="Reset"/>
</fieldset>
</form>
这是与之关联的视图配置:
@view_config(route_name='home', renderer='templates/home.pt')
def home(request):
choices=random.sample(ranges.items(),2)
choice1=choices[0]
choice2=choices[1]
output=request.GET["myradio"]
return {'choice1':choice1,'choice2':choice2, 'output':output, "myradio":myradio}
这给了我一个简单的KeyError: 'myradio'。
编辑:如果我需要更多详细信息,请随时询问。
【问题讨论】:
-
阅读 http 表单提交。 w3schools.com/html/html_forms.asp 并且您要查找的值将在您的视图函数中 request.POST 的字典中。
-
但它会是 request.POST[?]。会是 request.POST[choice1,choice2] 吗?它会输出一个布尔值、一个变量、一个字符串吗?
标签: python html unicode pyramid