【发布时间】:2012-03-26 11:02:16
【问题描述】:
在我的 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.com/whatever/blah/blah/?v1=0&v2=blah+blah ...
我应该得到:
- https://docs.google.com/
- https://stackoverflow.com/
- http://www.example.com
- https://www.other-domain.com/
我查看了其他相关问题并找到了有关 urlparse 的信息,但此后并没有解决问题
>>> urlparse(request.META.get('HTTP_REFERER')).hostname
'docs.google.com'
【问题讨论】: