Top Commentators

OnTheRoad

  • Two guys and a Beer - Episode 85
  • Jam Session 2
  • Two guys and a Beer - Episode 84

Django: Reverse HTTP redirect with parameters

Here’s how to, from a view, redirect to another URL passing parameters to it. For instance, to redirect the user to a certain page after login:

return HttpResponseRedirect(reverse('dz_details', kwargs={'dz_id':dz.id}))

This will lookup the ‘dz_details’ name in your urls.py file, which could be defined like so:

url(r'^details/(\d+)/$', views.dz_details, name='dz_details'),

There is a simpler way to do it, if you don’t want to use the parameters’ names, but you have to know the order on which they appear in the method:

return HttpResponseRedirect(reverse('dz_details', args=[ dz.id ]))

Related:

  1. [Django] Dynamic redirection after login Here’s how to redirect to the login page in django,...
  2. Java HTTP proxy servlet (with Spring) I always wanted to build my own proxy. I’m kidding....

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

1 comment to Django: Reverse HTTP redirect with parameters

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>