title: How to redirect to external URL in Django?
body: <p>I think this should be easy, but I cannot figure it out. I am trying to write an opt-out view. I am receiving a get request. Through urls.py, I render my opt-out view. In this view, I save some parameters for the user in the database and then I want to redirect the user to an external URL. I tried:</p>
  
  <pre><code>return redirect('http://stackoverflow.com/')
  </code></pre>
  
  <p>from <a href="https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#redirect" rel="noreferrer">Django documentation</a>. However, the optout view renders the training template instead of returning the redirect, though the parameters are saved in the database as expected. My code is as follows:</p>
  
  <pre><code>def optout(request):
      if (('REMOTE_USER' in request.META and request.META['REMOTE_USER'] != "") or 
          (request.session.get('userid', False) and request.session['userid'] != "")):
          if ('REMOTE_USER' in request.META and request.META['REMOTE_USER'] != ""):
              userid = request.META['REMOTE_USER']
          if (request.session.get('userid', False) and request.session['userid'] != ""):
              userid = request.session['userid']
          user = User.objects.get(username=userid)
          user.optout = True
          user.postpone = False
          user.save()
          return redirect('http://stackoverflow.com/')
      context = { 'userid': "" }
      return render(request, 'games/Training.html', context)
  </code></pre>
  
  <p>Any help is highly appreciated.</p>