Simple Django Website Use Google Maps API To Display Current Guest IP Location and Dockerizing It For Deploy By Docker

– Create new Django project and new app

-Configure new app on file

-Define new url for home page on

-Define function processing for home page:

+Get current IP by API from

+Get information about country, city and latitude/longitude by API from<ip>

+Support checking this information store on session cache if already exist not need to call API again(only load from cache and response for user) for reduce traffic for web server

-Log in to google cloud console and anable MAP API:

-Choose explore and enable API


– Choose Maps Embed API

-On API Dashboard choose Credentials for create API Key for use MAPS API service:

-Choose Create Credentials->API Key

-Click on new generated key for restrict to access MAP API Key and Save

-Create template home.html for display IP information:

Use generated key for call Google Maps Embed API and show by iframe on home.html

Source value of tag iframe to display is: src=”<your API Key>&center=10.8142,106.6438&zoom=9″

-Apply migrations and running server

-User first browse will show result not get from cache

-Reload page will get result from cache (not need call APT to get information of visitor IP again)

*Build Django Project Image Use For Running Container:

-Go to source folder and create new Dockerfile with below content:

            FROM python:3.8

            LABEL maintainer=’vmt1991′

            RUN pip install Django requests

            WORKDIR /sources

            COPY ./ /sources

            EXPOSE 8000

            CMD python runserver

-Build new image with command:

-Run new container with new image:

-Config nginx as reverse proxy routing traffic to this container:

Edit: /etc/nginx/nginx.conf

-Start service nginx and testing browse to url http://checkipapi.vmt.local


Please enter your comment!
Please enter your name here