Get referring URL for Flask request

前端 未结 2 1932
心在旅途
心在旅途 2021-01-01 15:12

When a user visits our site and signs up, how can I capture which website they came from?

Be it search, a PR website, etc. I don\'t care what page from our site they

2条回答
  •  迷失自我
    2021-01-01 15:22

    request.referrer contains the URL the request came from, although it might not be sent by the client for various reasons.

    The attribute takes its value from the Referer (not a typo!) header:

    referrer = request.headers.get("Referer")
    

    or, using the Flask shortcut:

    referrer = request.referrer
    

    See this tutorial for an example.

提交回复
热议问题