用戶經由一個複選框選擇的槽,並且還應該輸入用戶名,如示於下面的模板:如何在django中修復GET參數錯誤?
<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參數的視圖中有什麼不正確?
doh!感謝您的幫助 – sharataka
@sharataka很高興幫助:) –