We will pass data from the view method as a LIST, Dictionary, or SET object and bind data under the dropdown list, checkbox, Listbox and radiobutton.
We will write python code under HTML file using Jinja Tag.
Code for Views.py
from django.shortcuts import render
def index(request):
course = ['C','CPP','JAVA','PYTHON','PHP']
branch = ['VijayNagar','PALASIA','BHAWARKUA']
student = {'101':'Adarsh','102':'Parag','103':'Sunil','104':'Firoz'}
feed = {45000,12000,23000,11000,89000}
if request.method=="POST":
course1= request.POST["course"] #value from ddl
chkitem = request.POST.getlist("chk[]") #value from checkbox
chkitem1=''
for data in chkitem:
chkitem1 = chkitem1+data + " "
si= request.POST.getlist("sinfo[]") #value from listbox
s = ''
for data1 in si:
s=s+data1 + " "
fee = request.POST["r"]
output = "DDL " + course1 + ", CHECKBOX " + chkitem1 + ", LISTBOX DATA " +s + " ,RADIO BUTTON DATA "+fee
return render(request,"databinding/index.html",{'res':course,'res1':branch,'res2':student.items(),'res3':feed,'out':output})
return render(request,"databinding/index.html",{'res':course,'res1':branch,'res2':student.items(),'res3':feed})
POST Answer of Questions and ASK to Doubt