To create a web page to calculate Churn Rate using server-side scripts.
Churn Rate = (CustLost / InitCust) * 100
InitCust --> Initial Customers Count
CustLost --> Customers Lost Count
Clone the repository from GitHub.
Create Django Admin project.
Create a New App under the Django Admin project.
Create a HTML file to implement form based input and output.
Create python programs for views and urls to perform server side processing.
Receive input values from the form using request.POST.get().
Calculate the Result using the given formula.
Display the calculated result in the server console.
Render the result to the HTML template.
Publish the website in Localhost.
math.html
<html>
<head>
<title>Churn Rate</title>
</head>
<body>
<h1 align ="center">Churn rate calculation</h1>
<h2 align="center">Kapil Viknesh K R(26018791)</h2>
<form method="POST">
{% csrf_token %}
<label>Customers Lost Count=</label>
<input type="text" name="CustLost" value="{{CL}}"><br><br>
<label>Initial Customers Count=</label>
<input type="text" name="Initcust" value="{{IC}}"><br><br>
<input type="submit" value="calculate"><br><br>
<label>Churn Rate=</label>
<input type="text" name="ChurnRate" value="{{CR}}"><br><br>
</form>
</body>
</html>
views.py
from django.shortcuts import render
def Churn_rate(request):
CL = IC = CR = 0
if request.method == 'POST':
CL = float(request.POST.get('CustLost') or 0)
IC = float(request.POST.get('Initcust') or 0)
CR = round((CL / IC) * 100, 2) if IC != 0 else 0
print("Customers Lost Count =", CL)
print("Initial Customers Count =", IC)
print("Churn Rate =", CR)
return render(request, 'mathapp/math.html', {'CL': CL, 'IC': IC, 'CR': CR})
urls.py
from django.contrib import admin
from django.urls import path
from mathapp import views
urlpatterns = [path('', views.Churn_rate, name='Churn_rate'),]
The the web page to calculate Churn Rate using server-side scripts is created successfully.
.png)
.png)