Top Commentators

  • 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 ]))
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Posterous
  • Reddit
  • Twitter
  • HackerNews
  • FriendFeed
  • Hyves
  • RSS

Related:

  1. [Django] Dynamic redirection after login
  2. Java HTTP proxy servlet (with Spring)

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>