To design a website to calculate the power of a lamp filament in an incandescent bulb 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
<!DOCTYPE html>
<html>
<head>
<title>BMI Calculator</title>
<style>
body {
background-color:yellow;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.box {
background-color: Grey;
width: 400px;
padding: 25px;
border-radius: 20px;
text-align: center;
}
input {
margin: 8px;
padding: 10px;
width: 50%;
}
input[type="submit"] {
width: auto;
background-color: white;
color: Red;
cursor: pointer;
}
.result {
margin-top: 10px;
font-weight: 800;
}
</style>
</head>
<body>
<div class="box">
<h2>BMI CALCULATOR</h2>
<h3>Name: DHEENADHAYA S R</h3>
<h3>Reg No: 25017597</h3>
<form method="post">
{% csrf_token %}
<label>Height (cm):</label><br>
<input type="number" name="height" required>
<br>
<label>Weight (kg):</label>
<br>
<input type="number" name="weight" required>
<br>
<input type="submit" value="CALCULATE BMI">
</form>
<div class="result">
Your BMI: {{ bmi }}
</div>
</div>
</body>
</html>
views.py
from django.shortcuts import render
def bmi_calculator(request):
bmi = None
category = None
height = None
weight = None
if request.method == "POST":
height = float(request.POST.get("height"))
weight = float(request.POST.get("weight"))
bmi = round(weight / ((height/100) ** 2), 2)
print(f"height : {height} cm, weight : {weight} kg, bmi : {bmi}")
return render(request, "mathapp/math.html",{"bmi": bmi})
urls.py
from django.contrib import admin
from django.urls import path
from mathapp import views
urlpatterns = [
path("admin/", admin.site.urls),
path("bmi/", views.bmi_calculator, name="bmi_calculator"),
]
The program for performing server side processing is completed successfully.
.png)
.png)