我试图在表单中选择它们后显示多个复选框值,但我只能显示最后一个选定的值而不是多个选定的值。如何显示所有选定的值?
这是我的意见.py
def multi(request):
if 'hobbies' in request.GET and request.GET['hobbies']:
hob = request.GET.getlist('hobbies')
for h in hob:
message = 'You entered ..... %r' % h
else:
message = 'enterd wrong datails'
return HttpResponse(message)
我的模板是
<html>
<head>
<title>Search</title>
</head>
<body bgcolor='#455772' >
<form action="/multi/" method="get">
Hobbies:<input type='checkbox' name='hobbies' value='football'/>football <input
type='checkbox' name='hobbies' value='cricket'/>cricket<input type='checkbox'
name='hobbies'value='others'/>others<br>
<input type="submit" value="Submit">
</form>
</body>
</html>