Member-only story

Django — Get browser and OS info from the HTTP requests

Allwin Raju
3 min readMay 9, 2021

--

Photo by Firmbee.com on Unsplash

This blog post focuses on finding various information about the nature of the browser and os from which the HTTP requests are made. The following information can be obtained from the requests.

  1. If the device is a mobile/PC
  2. Browser name
  3. Browser version
  4. OS of the computer or mobile
  5. OS version
  6. Device name

Let us get started. There are actually two ways to obtain this information.

  1. The 'HTTP_USER_AGENT' header data from the request object
  2. Using a django-user-agents library.

Let us get started.

1. The 'HTTP_USER_AGENT' data from the header

In Django, each type of HTTP request is received at the backend via a request object. This request object will have various data such as the user, request body, header data, and much more.

The META object will have all the necessary header data. The browser type can be obtained from the header using this META object simply as

request.META['HTTP_USER_AGENT']

This will return us something like this.

--

--

No responses yet