I'm building a small app that at first displays the form containing the checkboxes and asks the user to select one or more of them and then displays the name of only selected ones.
-- This works fine. Now, I want to display the data only corresponding to the fields that the user has checked or selected. This creates problem as I'm not able to fetch the attributes or objects from the list object named ' info ' since it is list of unicode strings like [u'name', u'marks'] . In display.html {{ j.i }} is not being fetched as ' i ' isn't an object but unicode string whereas ( when tried in shell ) j.name, j.marks fetches the information marks and name being objects or attributes.
Templates :
# form.html
<form action='/info/display' method="get"><p><input type="checkbox" name="info" value="name"> Name </p><p><input type="checkbox" name="info" value="roll_no"> Roll No. </p><p><input type="checkbox" name="info" value="branch"> Branch </p><p><input type="checkbox" name="info" value="session"> Session </p><p><input type="checkbox" name="info" value="marks"> Marks </p><p><input type="checkbox" name="info" value="backlog"> Backlog </p><p> <input class="button" type="Submit" value="Submit"> </p></form># display.htmlYou selected for : {{ nothing }}{% for i in info %}{% for j in list %}<p> {{ j.i }} </p>{% endfor %}{% endfor %}{% if error %}Please select atleast one field.{% endif %}# views.pydef index(request):return render(request, 'index.html')def display(request):list = Student.objects.all()if 'info' in request.GET:info = request.GET.getlist('info')return render(request, 'display.html', { 'info': info, 'list':list })else:return render(request, 'display.html', {'error': True, 'nothing':'nothing'})
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/523ff8cd-14e7-48d7-8c4f-28e5d0f05c3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment