I want to pass a list through the url. But when i tried, i got some errors. So how can i do that. Somebody please help me..
this is my view
def add_student(request):
if request.method == 'POST':
student_list = []
student_name = request.POST.getlist('student_name')
student_phone = request.POST.getlist('student_phone')
zipped = zip(student_name,student_phone)
for student_name,student_phone in zipped:
student_object = Student(
student_name=student_name,
student_phone=student_phone
)
student_object.save()
student_list.append(student_object.id)
return HttpResponseRedirect(reverse('students:view_students', args=student_list))
**# in the above code it throwing some errors**
else:
return render(request,'students/add_student.html')
def view_students(request,student_list=None):
if student_list:
instances = Student.objects.filter(id__in=student_list)
else:
instances = Student.objects.filter()
context = {}
context['instances'] = instances
return render(request,'students/view_all_student.html',context)
this is my url :
url(r'^view-students/(?P<student_list>w+)/$',views.view_students, name='view_students'),
this is the error i got.
NoReverseMatch at /app/product/add-product/
Reverse for 'view_products' with arguments '(14, 15)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'app/product/view-products/(?P<pd_list>.*)/$']
here (14,15) are the list items.
If the question is not correct. Somebody please correct the question.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…