How do I get the user agent with Flask?

前端 未结 5 672
轻奢々
轻奢々 2020-12-02 09:35

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.

5条回答
  •  被撕碎了的回忆
    2020-12-02 10:06

    from flask import request
    request.headers.get('User-Agent')
    

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

提交回复
热议问题