0
我有一個根據日期提交表單的代碼。每當我使用分頁上formit顯示錯誤分頁在django中無法正常工作
"Key 'userchoice' not found in <QueryDict: {}>"
分頁限制的數據才能正常顯示,但是當我點擊「下一步」就顯示錯誤。
這裏是我到目前爲止有:
views.py: -
def testeruser(request):
getchoice = request.POST['userchoice']
getfirstdate = request.POST['firstdate']
getseconddate = request.POST['seconddate']
# getfirstdate = '2013-09-25'
# getseconddate = '2013-09-26'
if getchoice == '0':
getdata = applicationform.objects.filter(date__gte=getfirstdate , date__lte=getseconddate)
##### PAGINATION
searchpagination = Paginator(getdata ,3)
page=request.GET.get('searchpage')
try:
searchcontacts = searchpagination.page(page)
except PageNotAnInteger:
searchcontacts = searchpagination.page(1)
except EmptyPage:
searchcontacts = searchpagination.page(searchpagination.num_pages)
if getdata:
return render_to_response('registration/search_page.html', {'getdata':getdata ,'getchoice':getchoice ,'searchcontacts': searchcontacts})
else:
return HttpResponse('NO ITEMS FOUND ON THIS DATE')
在自定義模板: -
<form method="POST" action="/testeruser/" class="form-horizontal" name="searchform" enctype="multipart/form-data" >{% csrf_token %}
<select name="userchoice" id="client_specification" class="span2" required> <option value='-1'>Select Your Choice </option>
<option value='0'>Biddings</option>
<option value='1'>Interviews</option>
<option value='2'>Jobs</option>
</select>
From: <input type="text" class="input-xlarge" name="firstdate" id="search1" readonly="readonly" />
To: <input type="text" class="input-xlarge" name="seconddate" id="search2" readonly="readonly"/> </span>
<button class="btn btn-gebo" type="submit" name="asubmit" >Submit</button>
</form>
<!------------ PAGINATION---------------->
<div class="pagination">
<ul> {% if searchcontacts.has_previous %}
<li><a href="?searchpage={{ searchcontacts.previous_page_number }}">PREVIOUS</a></li>
{% endif %}
{% if searchcontacts.has_next %}
<li><a href="?searchpage={{ searchcontacts.next_page_number }}">NEXT</a></li>
{% endif %}
</ul>
</div>
<!------------ PAGINATION---------------->