To design a website to find total surface area of a square prism in server side.
Clone the repository from GitHub.
Create Django Admin project.
Create a New App under the Django Admin project.
Create python programs for views and urls to perform server side processing.
Create a HTML file to implement form based input and output.
Publish the website in the given URL.
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Area of Square Prism</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<style type="text/css">
body {
background-color:white;
}
.edge {
display: flex;
height: 100vh;
width: 100%;
justify-content: center;
align-items: center;
}
.box {
display: block;
width: 500px;
min-height: 300px;
font-size: 20px;
background: rgb(7,85,152);
background: linear-gradient(90deg, rgba(7,85,152,1) 9%, rgba(7,142,150,1) 56%);
border-radius: 10px;
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
}
.formelt {
color: whitesmoke;
text-align: center;
margin-top: 7px;
margin-bottom: 6px;
}
h1 {
color: white;
text-align: center;
padding-top: 20px;
}
input{
margin: 5px;
padding: 5px;
border-radius: 5px;
border: none;
}
</style>
</head>
<body>
<div class="edge">
<div class="box">
<h1>Area of a Square Prism</h1>
<form method="POST">
{% csrf_token %}
<div class="formelt">
Side : <input type="text" name="length" value="{{l}}"></input>(in m)<br />
</div>
<div class="formelt">
Height : <input type="text" name="breadth" value="{{b}}"></input>(in m)<br />
</div>
<div class="formelt">
<input type="submit" value="Calculate"></input><br />
</div>
<div class="formelt">
Area : <input type="text" name="area" value="{{area}}"></input>m<sup>2</sup><br />
</div>
</form>
</div>
</div>
</body>
</html>
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','0')
b = request.POST.get('breadth','0')
print('request=',request)
print('Length=',l)
print('Breadth=',b)
area = 2*(int(l)**2) + 4*int(l)*int(b)
context['area'] = area
context['l'] = l
context['b'] = b
print('Area=',area)
return render(request,'mathapp/index.html',context)
"""
URL configuration for mathser project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
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")
]
The program for performing server side processing is completed successfully.