How do I get the user agent with Flask?

前端 未结 5 680
轻奢々
轻奢々 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 09:59

    If you use

    request.headers.get('User-Agent')
    

    you may get: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36

    If you use

    request.user_agent
    

    you may get like this:

    • user_agent.platform: windows
    • user_agent.browser: chrome
    • user_agent.version: 45.0.2454.101
    • user_agent.language: None
    • user_agent.string: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36

提交回复
热议问题