title: How to redirect with request context to another url in Django
body: <p>I'm new to <code>Django</code>. Given a simple user login scenario. I have two templates: <code>index.html</code> and <code>register.html</code>.</p>
  
  <p>In <code>register.html</code>, it's just a simple user register web page and post the user data to a url:</p>
  
  <pre><code>&lt;form class="form-horizontal" action="/register/" method="post"&gt;
      ......
  &lt;/form&gt;
  </code></pre>
  
  <p>And in <code>index.html</code>, it shows the user information:</p>
  
  <pre><code>    {% if user.is_authenticated %}
          &lt;p&gt;Welcome, {{ user.username }}. Thanks for logging in.&lt;/p&gt;
      {% else %}
          &lt;p&gt;Welcome, new user. Please log in.&lt;/p&gt;
      {% endif %}
  </code></pre>
  
  <p>Here is the <code>urls.py</code>:</p>
  
  <pre><code>urlpatterns = patterns('',
      url(r'^$', views.index, name='index'),
      url(r'register/form/', views.register_form,name='register_form'),
      url(r'register/', views.register, name='register'),
  )+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
  </code></pre>
  
  <p>Here is the <code>views.py</code>:</p>
  
  <pre><code>def index(request):
      return render(request, 'index.html')
  
  
  def register_form(request):
      return render(request, 'register.html')
  
  
  def register(request):
      if request.method == 'POST':
  
          user = User.objects.create_user(username=request.POST['username'], password=request.POST['password'])
          user.save()
  
          user = authenticate(username=request.POST['username'], password=request.POST['password'])
          auth.login(request, user)
  
          return render_to_response('index.html', context_instance=RequestContext(request))
  </code></pre>
  
  <p>Here is my question:</p>
  
  <p>First, go to this url <code>register/form/</code> to fill in the form and submit the data, and then it'll go to url <code>register/</code> to process the data and then go to <code>index.html</code>. But the url in the browser is still <code>register/</code>.</p>
  
  <p>After register, I want the url is <code>my_domain_name/</code> rather than <code>my_domain_name/register/</code> because if it's still in <code>my_domain_name/register/</code>, if I refresh, it'll show whether to submit data again.</p>
  
  <p>Please help.</p>