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'})
else:
c=a+b
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>
<html>
<head>
<title></title>
</head>
<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
<br>
<input type="radio" name="ope" value="Add">Add
<br>
<button type="submit" name="btn">Click Here For Swapping</button>
</form>
{{k4}}
</body>
</html>
Right away I am ready to do my breakfast, afterward having my
ReplyDeletebreakfast coming over again to read other news.