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"

Django Program to perform addition using three buttons:



views.py code

from django.shortcuts import render

def index(request):
if request.method=='POST' 
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")


code of index.html

<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="/static/style.css"  type="text/css" rel="stylesheet" />
</head>
<body>
<header>

<center><h1>SI FORM </h1></center>
</header>
<section>
<div style="padding-top:50px;padding-left: 200px; ">
  <form action="" method="post">
  {% csrf_token  %}
    <input type="number" name="txtp" placeholder="Enter first number" required="" />
    <br><br>
    <input type="number" name="txtr" placeholder="Enter second number" required="" />
    <br>
     <br>
    <input type="submit" name="btnsubmit" value="+" />
     <br>
      <br>
    <input type="submit" name="btnsubmit" value="-" />
     <br>
      <br>
    <input type="submit" name="btnsubmit" value="*" />
  </form>
   {{res}}
</div>
  </section>
  <footer></footer>
</body>
</html>

code of urls.py

from django.urls import path
from . import views

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

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