title: Get protocol + host name from URL
body: <p>In my Django app, I need to get the host name from the referrer in <code>request.META.get('HTTP_REFERER')</code> along with its protocol so that from URLs like:</p>
  <ul>
  <li><code>https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1</code></li>
  <li><code>https://stackoverflow.com/questions/1234567/blah-blah-blah-blah</code></li>
  <li><code>http://www.example.com</code></li>
  <li><code>https://www.other-domain.example/whatever/blah/blah/?v1=0&amp;v2=blah+blah</code></li>
  </ul>
  <p>I should get:</p>
  <ul>
  <li><code>https://docs.google.com/</code></li>
  <li><code>https://stackoverflow.com/</code></li>
  <li><code>http://www.example.com</code></li>
  <li><code>https://www.other-domain.example/</code></li>
  </ul>
  <p>I looked over other related questions and found about urlparse, but that didn't do the trick since</p>
  <pre><code>&gt;&gt;&gt; urlparse(request.META.get('HTTP_REFERER')).hostname
  'docs.google.com'
  </code></pre>