Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 115 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,121 @@ Create a HTML file to implement form based input and output.
Publish the website in the given URL.

# PROGRAM :
math.html

<!DOCTYPE html>
<html>
<head>
<title>Area of Rectangle</title>

<style>
body {
font-size: 20px;
background-color: blue;
}

.formelt {
color: orange;
text-align: center;
margin-top: 7px;
margin-bottom: 6px;
}

h1 {
color: rgb(255, 0, 179);
text-align: center;
padding-top: 20px;
}

.box {
background-color: white;
width: 400px;
margin: auto;
padding: 20px;
border-radius: 10px;
}
</style>
</head>

<body>
<div class="edge">
<div class="box">

<h1>Area of a Rectangle</h1>

<form method="POST">
{% csrf_token %}

<div class="formelt">
Length :
<input type="text" name="length" value="{{ l }}">
(in m)
</div>

<div class="formelt">
Breadth :
<input type="text" name="breadth" value="{{ b }}">
(in m)
</div>

<div class="formelt">
<input type="submit" value="Calculate">
</div>

<div class="formelt">
Area :
<input type="text" name="area" value="{{ area }}" readonly>
m<sup>2</sup>
</div>
</form>

</div>
</div>
</body>
</html>

views.py

from django.shortcuts import render

def rectarea(request):
context = {}
context['area'] = "0"
context['l'] = "0"
context['b'] = "0"

if request.method == 'POST':
print("POST method is used")
l = request.POST.get('length', '')
b = request.POST.get('breadth', '')

print('request =', request)
print('Length =', l)
print('Breadth =', b)

area = int(l) * int(b)

context['area'] = area
context['l'] = l
context['b'] = b

print('Area =', area)

return render(request, 'mathapp/math.html', context)

urls.py

from django.contrib import admin
from django.urls import path
from mathapp import views

urlpatterns = [
path('admin/', admin.site.urls),
path('areaofrectangle/', views.rectarea, name="areaofrectangle"),
path('', views.rectarea, name="areaofrectangleroot"),
]
# SERVER SIDE PROCESSING:
# HOMEPAGE:
# HOMEPAGE: ![area](https://github.com/user-attachments/assets/0dfbdcae-0f21-4807-86f5-67ed3a3f55d0)

# RESULT:
The program for performing server side processing is completed successfully.