title: Python - if, elif, elif, else Statement Not Working as Expected
body: <p>I'm using Django for a web site and needed to build a context processor to provide referrer (variable named <code>referer</code>)  information.</p>
  
  <p>I have a simple if, elif, elif, else statement:</p>
  
  <pre><code>[ . . . ]
  
  host = get_current_site(request)
  local_url = SITE_URLS['local']
  dev_url = SITE_URLS['dev']
  prod_url = SITE_URLS['prod']
  
  # print referer for debugging purposes - remove when done...
  print("current host: {0}".format(host))
  print("current urls: {0} {1} {2}".format(local_url, dev_url, prod_url))
  
  # determine default referer - eg, set as host/site name
  if host == prod_url:
      referer = prod_url
  
  elif host == dev_url:
      referer = dev_url
  
  elif host == local_url:
      referer = local_url
  
  else:
      # set referer for current request
      try:
          referer = request.META['HTTP_REFERER']
  
      except KeyError as e:
          print('ERROR: key error - referer doesn\'t exist: {0}'.format(str(e)));
  
  [ . . . ]
  </code></pre>
  
  <p>What's weird is that the print statements above yield the <code>host</code> being equal to the <code>local_url</code> (from console):</p>
  
  <pre><code>current host: http://localhost:8000
  current urls: http://localhost:8000 [ . . . ]
  </code></pre>
  
  <p>Yet it is still evaluating the <strong>else > try</strong> and throwing a key error... The point is that only when the default host/site is not available, then the <code>request.META['HTTP_REFERER']</code> is valid.</p>
  
  <p>What is going wrong here? I'm missing something. Python is telling me that <code>host != local_url</code> but why?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks to a great hint from @Martijn Pieters. I changed the print statements and now see this:</p>
  
  <pre><code>current host: &lt;Site: http://localhost:8000&gt;
  current urls: 'http://localhost:8000'
  </code></pre>
  
  <p>I think I forgot to use the attributes for the sites framework:</p>
  
  <p><a href="https://docs.djangoproject.com/en/dev/ref/contrib/sites/" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/contrib/sites/</a></p>