title: Django HttpResponseRedirect vs render_to_response - how to get a login form to behave the way I need it to
body: <p>I've already checked out the following <a href="https://stackoverflow.com/questions/1921523/django-what-is-the-difference-b-w-httpresponse-vs-httpresponseredirect-vs-rende">stackoverflow question regarding the difference between HttpResponse, HttpResponseRedirect, and render_to_response</a>, as well as having gone through the official django docs, but I'm really uncertain how best to get the functionality I'm looking to create. </p>
  
  <p>Right now I have an <strong>index.html</strong> with a login function (as seen in the <strong>views.py</strong> below) where the <code>render_to_response</code> that brings me to <strong>portal/index.html</strong>. However, as <strong>urls.py</strong> (see below) dictates, the url in the url bar of my browser is <code>http://127.0.0.1:8000/login/</code>. This means that refreshing the page forces the form to go again. </p>
  
  <p>How do I get that url (once logged in) to look like <code>http://127.0.0.1:8000/</code> or, if that's not feasible, <code>http://127.0.0.1:8000/portal/</code> - this is because I think it's clumsy that every time you reload the page once logged in, it forces the browser to open the prompt <em>Are you sure you want to send a form again?</em>.</p>
  
  <p>Thank you so much for helping a Django newbie!</p>
  
  <p><strong>views.py</strong>  </p>
  
  <pre><code>@cache_page(60 * 15)
  def login_user(request):
      #inactive_image_url = ""
      #invalid_credentials_url = ""
      context_instance=RequestContext(request)
      if request.POST:
          username = request.POST.get('username')
          password = request.POST.get('password')
          user = authenticate(username=username, password=password)
          if user is not None:
              if user.is_active:
                  login(request, user)            
                  state = "You're successfully logged in!"
                  return render_to_response('ucproject/portal/index.html', 
                          {'state':state, 'username':username}, context_instance=RequestContext(request))
              else:
                  #state_img = inactive_image_url
                  state = "Your account is not active, please contact UC admin."
          else:
              #state_img = invalid_credentials_url
              state = "Your username and/or password were incorrect."
      return render_to_response('ucproject/index.html', 
              {'state': state,
               #'state_img': state_img,
               'username': username
              }, context_instance=RequestContext(request))
  
  def portal(request):
      username = 'username'
      return render_to_response('ucproject/portal/index.html', 
              {'state': state,'username': username}, context_instance=RequestContext(request))
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code># Login / logout.
  url(r'^registration/$', 'portal.views.registration'),
  url(r'^login/$', 'portal.views.login_user'),
  url(r'^portal/$', 'portal.views.portal'),
  url(r'^portal/index.html$', 'portal.views.portal'),
  </code></pre>