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.
bmi.html
<html>
<head>
<title>
BMI Calculation
</title>
<style>
body{
background-color:rgb(197, 240, 255);
}
.box{
margin-left:523px;
border: 8px dashed rgb(13, 67, 87);
width:350px;
height:220px;
text-align:center;
padding:50px;
}
</style>
</head>
<body>
<h1 align="center">Body Mass Index</h1>
<h2 align="center">Janesha S (25018817)</h2>
<br><br><br><br>
<div class="box">
<h2>BMI Calculation</h2>
<form method="post" align="center">
{% csrf_token %}
<label for="height">Height(in m):</label>
<input type="text" name="height" value="{{ height }}">
<br><br>
<label for="weight">Weight(in kg):</label>
<input type="text" name="weight" value="{{ weight }}">
<br><br>
<input type="submit" value="Calculate BMI">
<br><br>
<label for="bmi">BMI(in kg/m^2):</label>
<input type="text" name="bmi" value="{{ bmi }}" readonly>
</form>
</div>
</body>
</html>
views.py
from django.shortcuts import render
def calculate_bmi(request):
bmi=None
height=''
weight=''
if request.method == "POST":
height = float(request.POST.get("height"))
weight = float(request.POST.get("weight"))
bmi=(weight/height**2)
print(f'''Height:{height},
Weight:{weight},
BMI:{bmi:.2f}''')
return render(request, 'mathapp/bmi.html', {
'bmi': bmi,
'height': height,
'weight': weight
})
urls.py
from django.contrib import admin
from django.urls import path
from mathapp import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.calculate_bmi, name='BMI'),
]
The program for performing server side processing is completed successfully.
.png)
.png)