1)  code of views.py

from django.shortcuts import render
from django.http import HttpResponse

def swapform(request):
if request.method=='POST':
a = int(request.POST["t1"])
b = int(request.POST["t2"])
if request.POST["ope"]=="swap":
a = a + b
b = a - b
a = a - b
return render(request,"swapapp/swa.html",{'k1':a,'k2':b,'k3':'cyan'})
return render(request,"swapapp/swa.html",{'k1':a,'k2':b,'k3':'orange','k4':c})
return render(request,"swapapp/swa.html")

2)  Code of swa.html

<!DOCTYPE html>
<body bgcolor="{{k3}}">
<form action="#" method="POST">
{% csrf_token %}

ENTER 1ST no.<input type="text" name="t1" value="{{k1}}"><br>
ENTER 2ND no.<input type="text" name="t2" value="{{k2}}"><br><br>
<input type="radio" name="ope" value="swap">SWAP
<input type="radio" name="ope" value="Add">Add
<button type="submit" name="btn">Click Here For Swapping</button>




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