To design a website to calculate the power of a lamp filament in an incandescent bulb in the server side.
P = I2R
P --> Power (in watts)
I --> Intensity
R --> Resistance
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>
<head>
<style>
body{
background-color:pink;
}
.formelt{
color:black;
text-align: center;
margin-top: 7px;
margin-bottom: 6px;
}
h1{
color:purple;
text-align: center;
padding-top: 20px;
}
</style>
</head>
<body>
<div class="edge">
<div class="box">
<h1>BMI Calculation (BMI = w / h^2 )</h1>
<br>
<h3 align="center">Gaushika RR (25017292) </h3>
<form method="POST">
{% csrf_token %}
<div class="formelt">
weight (w): <input type="text" name="weight" value="{{w}}">(in kg)<br/>
</div>
<div class="formelt">
height (h): <input type="text" name="height" value="{{h}}">(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}}">(in kg/m^2 )<br/>
</div>
</form>
</div>
</div>
</body>
</html>
views.py
from django.shortcuts import render
def BMIcalc(request):
context = {}
context['BMI'] = "0"
context['w'] = "0"
context['h'] = "0"
if request.method == 'POST':
print("POST method is used")
w = request.POST.get('weight', '0')
h = request.POST.get('height', '0')
print('weight =', w)
print('height =', h)
BMI = (int(w) ) / (float(h)**2)
context['BMI'] = BMI
context['w'] = w
context['h'] = h
print('BMI =', BMI)
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('BMI/', views.BMIcalc, name="BMIcalc"),
path('', views.BMIcalc, name="BMIcalcroot"),
]
The program for performing server side processing is completed successfully.