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>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Power of a Lamp Filament</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<style type="text/css">
body
{
background-color:pink;
}
.edge {
width: 1440px;
margin-left: auto;
margin-right: auto;
padding-top: 250px;
padding-left: 300px;
}
.box {
display:block;
border: Thick dashed slategrey;
width: 500px;
min-height: 300px;
font-size: 20px;
background-color:white;
}
.formelt{
color:black;
text-align: center;
margin-top: 7px;
margin-bottom: 6px;
}
h1
{
color:rgb(255, 0, 179);
text-align: center;
padding-top: 20px;
}
</style>
</head>
<body>
<div class="edge">
<div class="box">
<h1>Power of a Light Filament</h1>
<form method="POST">
{% csrf_token %}
<div class="formelt">
intensity : <input type="text" name="intensity" value="{{i}}"></input>(in Wm<sup>-2</sup>)<br/>
</div>
<div class="formelt">
resistance : <input type="text" name="resistance" value="{{r}}"></input>(in ohm)<br/>
</div>
<div class="formelt">
<input type="submit" value="Calculate"></input><br/>
</div>
<div class="formelt">
Power : <input type="text" name="power" value="{{power}}"></input>(in W)<br/>
</div>
</form>
</div>
</div>
</body>
</html>
views.py
from django.shortcuts import render
def lightpower(request):
context={}
context['power'] = "0"
context['i'] = "0"
context['r'] = "0"
if request.method == 'POST':
print("POST method is used")
i = request.POST.get('intensity','0')
r = request.POST.get('resistance','0')
print('request=',request)
print('intensity=',i)
print('resistance=',r)
power = (int(i) * int(i)) * (int(r))
context['power'] = power
context['i'] = i
context['r'] = r
print('power=',power)
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('poweroflight/',views.lightpower,name="poweroflight"),
path('',views.lightpower,name="poweroflightroot")
]
The program for performing server side processing is completed successfully.
-1.png)
