request.POST returning queryDict how do i get the values of the attributes
views.py
def tutorial(request,id):
mo=Course.objects.get(courseId=id).student.all()
ob=Tutorial.objects.filter(course__courseId=id)
if request.method=="POST":
for o in request.POST:
print(o)
ss="/nonCourseDetail/"+str(id)
response=redirect(ss)
return response
cont={'mo':mo,
'ob':ob}
return render(request,'tutorial.html',cont)
output from terminal
csrfmiddlewaretoken
tutorial
attendance
final
If this is a form (or form data) being submitted, I would suggest using the form.
Otherwise, see HttpRequest.POST
It was supposed return queryset of objects
here in the html code
<form method="POST">
{%csrf_token%}
<table>
{%for o in ob%}
<tr>
<th><input type="number" name="id" placeholder="{{o.student.studentId}}"" disabled ></th>
<th><input type="text" name="name" placeholder="{{o.student.name}}"" disabled></th>
<th><input type="number" max="30" step=".01" name="tutorial" value={{o.tutorial}} ></th>
<th><input type="number" max="10" step=".01" name="attendance" value={{o.attendance}}></th>
<th><input type="number" max="60" step=".01" name="final" value={{o.final}}></th>
</tr>
{%endfor%}
</table>
<button type="submit">Save</button>
</form>
You have the problem here in that every instance in your set is going to have the same name
attribute for the values being submitted.
If you’re creating a form for multiple instances of the same type of objects, you want to look at Django’s formsets.
What you don’t want to do in Django is manually render input fields individually as html elements.