我试图过滤一些值并将这些值保存在会话变量中,以便在Excel工作表中写入这些值,也可以用于无限的分页。有时候查询设置值达到了近55000.那时django显示内部服务器错误。< / p>
views.py
def search(request,template='admin/search.html', page_template='pagination/paginate_student.html'):
rg = request.POST.get
skill = rg('skills')
students_list = []
ec_students = EcStudentProfile.objects.filter(Q(Technical_skills__icontains=skill))
cs_students= CsStudentProfile.objects.filter(Q(jobrole__icontains=skill))
me_students = MeStudentProfile.objects.filter(
Q(jobrole__icontains=skill))
results = list(chain(ec_students, cs_students, me_students))
for result in results:
students_list.append(result)
if students_list:
request.session['list'] = students_list
students_list = request.session['list']
if 'excel' in request.POST:
students_list = request.session['list']
response = HttpResponse(content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=Report.xlsx'
xlsx_data = WriteToExcel(students_list)
response.write(xlsx_data)
return response
if request.is_ajax():
students_list = request.session['list']
template = page_template
return render_to_response(template,
{'page_template': page_template, 'students_list': students_list}, context_instance=RequestContext(request))