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