Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Html Form Element in Django Application:-

In this article, we  define complete HTML elements using Textbox, Radiobutton, Checkbox, Listbox, Textarea, etc


To run this article code, you should have basic knowledge of HTML then you can click on the below link where I have to write articles of HTML code.







1)  Code of Design File:-

reg.html:-

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="reglogic" method="post">
{% csrf_token  %}
<input type="radio" name="course" value="PYTHON" />PYTHON<input type="radio" name="course" value="PHP" />PHP<br><br>
<input type="checkbox" name="c[]" value="C" />C<input type="checkbox" name="c[]" value="CPP" />CPP<input type="checkbox" name="c[]" value="DS" />DS<br><br>
<select name="country">
<option value="">Select Country</option>
    <option value="India">India</option>
    <option value="USA">USA</option>
    <option value="CHINA">CHINA</option>
</select>
<br><br>
<select name="state[]" multiple="">

    <option value="MP">MP</option>
    <option value="UP">UP</option>
    <option value="AP">AP</option>
    <option value="HP">HP</option>
</select>
<br><br>
<textarea name="txtpost"> </textarea>
<br><br>
<input type="submit" name="btnsubmit" value="Click" />
</form>
</body>
</html>


2)

from django.shortcuts import render

def index(request):
if request.method=='POST' and request.POST['btnsubmit']:
p = request.POST["txtp"]
r = request.POST["txtr"]
if request.POST['btnsubmit']=='+':
c=int(p)+int(r)
elif request.POST['btnsubmit']=='-':
c=int(p)-int(r)
elif request.POST['btnsubmit']=='*':
c=int(p)*int(r)
return render(request,"siapp/index.html",{'res':c})
return render(request,"siapp/index.html")
def reg(request):
return render(request,"siapp/reg.html")
def reglogic(request):
s = request.POST["course"]
cmb=request.POST["country"]
msg = request.POST["txtpost"]
s1=''
data = request.POST.getlist('c[]')
for d in data:
s1=s1+d+" "
st = request.POST.getlist('state[]')
stdata=''
for d in st:
stdata=stdata+d+" "
return render(request,"siapp/reglogic.html",{'res':s+' '+s1+' '+cmb+' '+stdata+' '+msg})



3)

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
{{res}}
</body>
</html>


4) 

from django.urls import path
from . import views

urlpatterns=[
  path('',views.index,name='index'),
  path('home',views.index,name='index'),
  path('reg',views.reg,name='reg'),
  path('reglogic',views.reglogic,name='reglogic')
 



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post