In this article, We will learn how to retrieve call logs from Twilio and show it on a webpage using the Django web framework
Ok let’s get started
Step 1: Create a Django Project
pip install django
django-admin startproject twiliocalllogs
python manage.py migrate
python manage.py runserver
if everything went well, you should see the above webpage. if it doesn’t refer https://www.djangoproject.com/start/
Step 2: Create a Django App
python manage.py startapp calllogs
update settting.py by adding the app name “calllogs” in Installed_apps
Step 3: Write a python function to retrieve call logs from Twilio
Navigate to calllogs directory and create a service.py file
Copy the above code to service.py and install twilio using “pip install twilio” and update “twilio” in Installed_apps.
Step 4: Final Part (View and Templates)
Now that we have taken care of the backend. Let’s move on to views and templates(HTML)
Create a templates directory in calllogs and create a logs.html file
Copy the html code to logs.html
Copy the above code in views.py. “GetLogs” class extends the TemplateView and renders it onto the logs.html. We will call the get_logs from service.py and pass the output of the function onto the view using the above code.
Add the above HTML code in the logs.html. Add it inside the <nav> tag to format the data. I have selected only a few variables. Please refer to https://www.twilio.com/docs/voice/tutorials/how-to-retrieve-call-logs-python for more variables.
Finally add a path in urls.py (twiliocalllogs)
Moment of Truth:
The blur lines are intentional to hide the data. That’s it.
Here is the Git Repo: https://github.com/govardhananam/Twilio-Call-Logs-Django/tree/main
Download and run: python manage.py runserver