Django model object hit counting


In this article, we are going to make a project in which we will see how to make a Django table that will store all the data of hit count and detailed data of hit. It can be used generate useful reports. So, let's get started.

Setup your urls.py and install the django-hitcount module

pip install django-hitcount

Example

In settings.py, add the following line −

INSTALLED_APPS+ = ['hitcount']

Here we added this library as an app in the project.

Run the following commands −

python manage.py makemigrations
python manage.py migrate

Here, we create migrations and then we migrate it.

That's all. This library will create a table that will store all the data.

Output

Go to http://127.0.0.1 and login

Hit counts and Hits contain what we wanted, you can explore other two.

Updated on: 25-Aug-2021

365 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements