To design a website to calculate the BODY MASS INDEX(BMI) in the server side.
BMI = W/H2
BMI --> Body Mass INdex
W --> Weight
H --> HEight
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.
math.html
<html>
<title>Body Mass Index</title>
<style>
body
{
background-color:pink;
}
.edge {
width: 1650px;
margin-left: auto;
margin-right: auto;
padding-top: 400px;
padding-left: 350px;
}
.box {
display:block;
border: solid 7px red;
width: 700px;
min-height: 400px;
font-size: 40px;
background-color: yellow;
}
.formelt{
color: blue;
text-align: center;
margin-top: 7px;
margin-bottom: 7px;
}
</style>
</head>
<body>
<div class= "edge">
<div class= "box">
<h1>Body Mass Index</h1>
<h2>V.Vashmitha(25015828)</h2>
<form method="POST">
{% csrf_token %}
<div class= "formelt">
Weight: <input type= "text" name="Weight" value="{{Weight}}"></input>(in kg)<br/>
</div>
<div class= "formelt">
Height: <input type="text" name="Height" value="{{Height}}"></input>(in m)<br/>
</div>
<div class= "formelt">
<input type="submit" value="Calculate"><br/>
</div>
<div class= "formelt">
bmi: <input type="text" name="bmi" value="{{bmi}}" align:"center"></input>kg/m<sup>3</sup><br/>
</div>
</form>
</div>
</div>
</body>
</html>
views.py
from django.shortcuts import render
def calculate_BMI(request):
bmi=None
Weight=None
Height=None
if request.method == 'POST':
print("POST method is used")
Weight=float(request.POST.get("Weight"))
Height=float(request.POST.get("Height"))/100
bmi = Weight/(Height**2)
bmi =round(bmi,2)
print(f"1Weight in kg: {Weight} ,Height in m: {Height},bmi: {bmi}")
return render(request,'myapp/math.html',{'bmi':bmi})
urls.py
from django.contrib import admin
from django.urls import path
from myapp import views
urlpatterns=[
path('admin/', admin.site.urls),
path('',views.calculate_BMI,name="home"),
path('bmi/', views.calculate_BMI,name='bmi')
]
The program for performing server side processing is completed successfully.
.png)
.png)