views:

114

answers:

1

I have a form in which the user selects a few items to display on "the following page". This selection is always unique, and we will store each set of selections made using a model, indexed by the id as is par with Django models. When the user selects her choices and POSTs using the submit button, I would like for our application to store her selections in the model, and then render a page with the id of the model so that the user can get back to the page she created at any point with a simple GET request.

For example, the user goes to /coolapp/selectprefs/, makes a few selections, and clicks submit. The user should then be taken to /coolapp/selections/42 given that when the user submitted and created the record, the record was given an id of 42.

What I don't understand is how to send the user to "the following page" as a response (e.g., /coolapp/selections/42 in the above example) after she clicks the submit button. Taking a user to a page of a unique ID based on what she entered seems like a common task (e.g., it will happen when I click the button to submit this question on SO), but I'm not sure how to go about doing it, and would appreciate your advice.

+7  A: 

Return a HttpResponseRedirect from your view that handles the POST.

Brian Neal
Thanks, Brian! This got me on the right track. It looks like there's a nice shortcut for this, too: http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect
gotgenes
Cool, I didn't know about this new shortcut. :)
Brian Neal