title: How to redirect in django along with the request object
body: <p>I am facing a problem regarding the redirects in django.I am using an ajax call to login and in return i am getting a json on failure and on success a template.</p>
  
  <p>But On Success the response is getting rendered as html instead it should redirect to home page using <code>render_to_response</code>.</p>
  
  <h1>i tried</h1>
  
  <p>Using <code>HttpResponseRedirect</code> i don't get a request object and hence i can't get the session parameter which is my requirement.</p>
  
  <h1>Note: This might have some typos as i renamed some variables for confidentiality.</h1>
  
  <h1>View</h1>
  
  <pre><code>def sign_in(request):
      """
      :param request: data(json)
      """
      response_data = None
      if request.method == 'POST':
          print "Request Landed"
          data = request.POST.get('data', None)
          data = json.loads(data)
          username = data.get("username", None)
          password = data.get("password", None)
          user = auth.authenticate(username=username, password=password)
          if user is not None:
              if user.is_active:
                  auth.login(request, user)
                  context = RequestContext(request)
                  context_dict = {}
                  request.session['username'] = username
                  request.session['dd_id'] = str(P.objects.get(username=username).dd_id)
                  return render_to_response("p/home.html", context_dict, context)
              else:
                  response_data = json.dumps({'status': 'NOT OK', 'reason_phrase': 'Account confirmation is pending at '
                                                                                   'your end.Please check your email '
                                                                                   'address for confirmation link.'})
          else:
              response_data = json.dumps({'status': 'NOT OK', 'reason_phrase': 'Invalid Credentials!'})
      else:
          response_data = json.dumps({'status': 'NOT OK', 'reason_phrase': 'Invalid Request type!'})
      return generate_response(response_data=response_data)
  </code></pre>
  
  <h1>Update</h1>
  
  <p>I used a ajax request and sent a redirect on failure for a json to show invalid details error and render_to_response in case of success.Failure works fine but on success i am seing the template that is being sent by render_to_response on the same page....How to cope with that..</p>
  
  <p>Can anyone help me?</p>