repalviglator repalviglator - 1 year ago 388
Python Question

How do I get the user agent with Flask?

I'm trying to get access to the user agent with Flask, but I either can't find the documentation on it, or it doesn't tell me.

Answer Source
from flask import request

You can also use the request.user_agent object which contains the following attributes which are created based on the useragent string:

  • platform (windows, linux, macos, etc.)
  • browser (chrome, firefox, msie, etc.)
  • version
  • language
  • string (== request.headers.get('User-Agent'))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download