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>
<title>mathapp</title>
<style>
body{
background-color: yellow;
}
h1{
background-color: pink;
}
form{
background-color: red;
}
</style>
</head>
<body>
<h1 align="center">CALCULATION OF POWER</h1>
<form align="center"method="POST">
{% csrf_token %}
Intensity <input name="I" value="{{i}}">
<br>
<br>
Resistance<input name="R" value="{{r}}">
<br>
<br>
<input type="submit" value="calculate">
<br>
<br>
power<input name="Power"value={{power}}>
</form>
</body>
</html>
views.py
from django.shortcuts import render
def CalculationPower(request):
context={}
context['power'] = "0"
context['i'] = "0"
context['r'] = "0"
if request.method == 'POST':
print("POST method is used")
i = request.POST.get('I','0')
r = request.POST.get('R','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('CalculationPower/',views.CalculationPower,name="CalculationPower"),
path('',views.CalculationPower,name="CalculationPower")
]
The program for performing server side processing is completed successfully.
.png)
.png)