最佳答案
在我的Django应用程序中,我需要从request.META.get('HTTP_REFERER')
中的引用者及其协议中获取主机名,以便从URL中获取:
https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1
https://stackoverflow.com/questions/1234567/blah-blah-blah-blah
http://www.example.com
https://www.other-domain.example/whatever/blah/blah/?v1=0&v2=blah+blah
我应该得到:
https://docs.google.com/
https://stackoverflow.com/
http://www.example.com
https://www.other-domain.example/
我查看了其他相关问题,发现了关于URLParse的问题,但这并没有起到作用,因为
>>> urlparse(request.META.get('HTTP_REFERER')).hostname
'docs.google.com'