Django throws internal 500 error while saving heavy data in session variable

362 views Asked by At

I am trying to filter some values and holding these values in session variable for writing these values in a excel sheet and also for endless pagination.Some times the query set values reaches nearly 55000.that time django shows internal server error.

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))
0

There are 0 answers