In my recent django project, I needed to show timestamps in user's timezone. I thought it will be easier. But it took some time for me to figure out it. I'm listing the steps I followed to achieve that. This may help someone.

Packages/Services used

Step 1: Get user timezone

You can get user timezone from freegeoip API by making a get request to the API.

400: Invalid request

Step 2: Activate timezone

Then activate the timezone using the command

400: Invalid request

You can write a middleware to do this so that the timezone is activated. The middleware code can be like this.

400: Invalid request

Freegeoip provides 10,000 requests per hour by default. So if you need more number of requests, you may have to try some other API.

Now we have implemented middleware to get and activate user timezone in django. Feel free to post your comments.