repalviglator repalviglator - 2 months ago 37
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.

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'))