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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can also use the
request.user_agentobject which contains the following attributes which are created based on the useragent string:== request.headers.get('User-Agent'))Note: As of werkzeug 2.0, the parsed data of
request.user_agenthas been deprecated; if you want to keep getting details you need to use a customUserAgentimplementation and set it asuser_agent_classon a customRequestsubclass, which is set asrequest_classon theFlaskinstance (or a subclass).Here’s an example implementation that uses
ua-parser: