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
<!DOCTYPE html>
<html>
<head>
<title>Lamp Power Calculator</title>
</head>
<body style="text-align:center; margin-top:50px; background: linear-gradient(to right, black, grey, white, sandybrown);">
<h2>Power of Lamp Filament</h2>
<p><b>Formula:</b> P = I² × R</p>
<form method="post">
{% csrf_token %}
<label style="font-size: large;">Current (I in Amperes):</label><br>
<input type="number" name="current" step="0.01" required width: 250px; height: 30px; font-size: 16px;><br><br>
<label style="font-size: larger;">Resistance (R in Ohms):</label><br>
<input type="number" name="resistance" step="0.01" required width: 250px; height: 30px; font-size: 16px><br><br>
<button type="submit" aria-setsize="50">Calculate The Power</button>
</form>
<h3>Power: {{ Power }} W</h3>
</body>
</html>
views.py
from django.shortcuts import render
def calculate_power(request):
power = None
if request.method == "POST":
current = float(request.POST.get("current")) # I
resistance = float(request.POST.get("resistance")) # R
power = (current ** 2) * resistance # P = I² × R
print(f"Current: {current} A, Resistance: {resistance} Ω, Power: {power:.2f} W")
return render(request, 'math.html', {'Power': power})
urls.py
from django.contrib import admin
from django.urls import path
from app1 import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.calculate_power),
]
The program for performing server side processing is completed successfully.