Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variables to a "success" page after processing a form in Django

Is there anyway to pass context variables to a redirect response? I want to redirect a user to a success page after they submit a form, but I don't want the success page to be just a static html file. I need to display extra information based on the form data.

I have looked at this question, but the solution presented there simply renders a different file at the same url. I'd like to redirect the user so that hitting refresh at the page won't submit duplicate entries into the application.

Right now the only thing I have been able to use with some success is redirecting to a url while passing it GET variables as described here. That just seems like a bit of a hack, and was just wondering if there is any better solution...

Thank You

like image 306
chandsie Avatar asked Jan 21 '23 00:01

chandsie


2 Answers

The way I see it you have three options:

  1. Use GET variables in the redirect.
  2. Store something in the session.
  3. If you are creating an object using the form that was submitted, put the id of that object in the redirect url and use it in the new view.

The limitation you are running up against is that http is stateless, not something inherent in django.

like image 86
Sean W. Avatar answered Jan 31 '23 09:01

Sean W.


How about storing your values in a session, then have the redirected page pick up the values from there?

like image 44
Chris Curvey Avatar answered Jan 31 '23 08:01

Chris Curvey