Django IP Address Lookup Application

In this Django article we are going to learn about IP Address Lookup Application , so for creating

IP Finder Application we are going to use ipapi library.

 

 

Learn Django REST Framework for Beginner in Python 

 

 

Also you can read more django articles

1: Django Pagination Complete Example

2: Django Sending Email to Gmail Account 

3: Build News Application in Django 

4: Django Aggregation Example

5: Django User Authentication Framework 

 

 

 

 

Installation 

First of all you need to install ipapi library, you can use pip for the installation.

 

 

 

 

So after installation you need to create a New Project in Django, you can use this command

for creating of the Project in Django.

 

 

 

 

After creating of Django Project you need to change directory to the created Project, basically

we are going to create Django App. 

 

 

 

 

 

First of all you need to create a templates folder in your Project. and add two html files in

the templates folder. the first one is base.html and the second one is index.html, this is the 

structure of our Django Project.

Django Project Structure
Django Project Structure

 

 

 

 

 

Also after creating of the templates folder, you need to tell Django about this folder, so open

your settings.py file, and in the TEMPLATES you need to add your templates name like this.

 

 

 

 

 

So now open your views.py file in your Django App, in our case the App name is IPApp and

add this code. basically in the Index view function we are going to first get the input from user,

right now we have not created our html code, after that we use our ipapi library for finding the

IP locations and information. also you need to send the information in your index.html.

 

 

 

 

Now this is our base.html. also we have used Bootstrap CDN linke in here.

 

templates/base.html

 

 

 

 

 

And this is the index.html, basically we have a text input field for searching IP Address, also we

are rendering the data in our index.html file.

 

templates/index.html

 

 

 

 

Now we need to create our url routing, first you need to create a new python file at name

of urls.py in your Django App, in my case it is IPApp, and add this code.

 

 

 

 

 

And this is our Project urls.py, basically we have included our App urls.py in here using

include method.

 

 

 

So now run your Django Project.

 

 

 

 

Go to http://localhost:8000/  and this will be the result.

Django IP Address Lookup Application
Django IP Address Lookup Application

 

 

 

 

 

Also you can watch the complete video for this article 

Subscribe and Get Free Video Courses & Articles in your Email

 

1 thought on “Django IP Address Lookup Application”

  1. Thanks for this tutorial. How do i implement IP redirect based on region the website visitors are coming from?

Comments are closed.

Share via
Copy link
Powered by Social Snap
×