2
votes

I have tried using request.META['HTTP_USER_AGENT'] for detecting the browser . But this returns the type of browsers list when i tested on

chrome: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

instead of just returning chrome and similarly on :

edge: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299

mozilla: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0

** I am not able to get the pattern in which it is returning values. Can anyone tell the way by which i could get the browser name

1
This doesn't really have to do with Django. What you want is a User Agent string database that will map a User Agent string to a reasonable browser family. However, as I'm sure many other web developers will tell you, trying to guess the browser from the UA string is mostly an exercise in vain.Kal
Maybe you are interested in reading about why the user agent string is such a mess: reddit post why_every_user_agent_string_start_with_mozilla and direct link to the articleRalf

1 Answers

1
votes

You can use request object for the same:

request.META['HTTP_USER_AGENT']

also there is a package for that : django-user-agents