我有一个根据日期提交表单的代码。每当我在表单上使用分页时都会显示错误
"Key 'userchoice' not found in <QueryDict: {}>"
分页限制数据正确显示,但是当我单击“下一步”时,它会显示错误。
这是我到目前为止所得到的:
视图.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---------------->