[Fixed]-How to put several objects in one template

1👍

As I see you have two models Class and Student. In this case better way to create custom view:

def myCustomView(request, pk):
  get_class = get_object_or_404(Class, pk=pk)
  student_form = StudentForm
    if request.POST:
      student_form = StudentForm(request.POST)
      if student_form.is_valid():
        ...
        return ...
      else:
        return render(request, 'index.html', {'get_class':get_class, 'student_form':sudent_form})
    else:
      return render(request, 'index.html', {'get_class':get_class, 'student_form':sudent_form})

Leave a comment