我有以下 HTML 代码:
<form method="post">
<h5>Sports you play:</h5>
<input type="checkbox" name="sports_played" value="basketball"> basketball<br>
<input type="checkbox" name="sports_played" value="football"> football<br>
<input type="checkbox" name="sports_played" value="baseball"> baseball<br>
<input type="checkbox" name="sports_played" value="soccer"> tennis<br>
<input type="checkbox" name="sports_played" value="mma"> MMA<br>
<input type="checkbox" name="sports_played" value="hockey"> hockey<br>
<br>
<input class="btn" type="submit">
</form>
然后理想情况下,我想拥有以下 python 服务器端代码:
class MyHandler(ParentHandler):
def post(self):
sports_played = self.request.get('sports_played')
#sports_played is a list or array of all the selected checkboxes that I can iterate through
我尝试通过创建 HTML sports_played 名称和数组 sports_played[] 来做到这一点,但这并没有做任何事情,现在它总是返回第一个选定的项目。
这可能吗?真的,我只是不想为每个复选框都做一个 self.request.get('HTML_item') 以防我需要更改我不想更改 python 的 HTML。
谢谢!