用户通过复选框选择一个插槽,还应该输入一个用户名,如下面的模板所示:
<form action="/clubs/{{ club.id }}/vote/" method="post">
{% csrf_token %}
{% for slot in tom_open_slots %}
<input type="checkbox" name="slot" id="slot{{ forloop.counter }}" value="{{ slot.id }}" />
<label for="slot{{ forloop.counter }}">{{ slot.slot }} on Court {{slot.court}}</label><br />
{% endfor %}
<input type="text" name="username" />
<input type="submit" value="Reserve" />
然后我想显示在复选框中输入的用户名和时间。我通过下面的视图和模板执行此操作:
def vote(request, club_id):
if 'username' in request.GET and request.GET['username'] and 'slot' in request.GET and request.GET['slot']:
username = request.GET['username']
slot = request.GET['slot']
return render_to_response('reserve/templates/vote.html',{'username':username, 'slot':slot})
else:
return HttpResponse('Please enter a username and select a time.')
{{slot}}
{{username}}
但是,当我转到 vote.html 时,我总是会收到错误消息(请输入用户名并选择时间)。没有获取 2 个 GET 参数的视图中有什么不正确的?