Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove confirm form resubmission with Python Bottle framework

I have:

  • page1: submits a form

  • page2: validates it and and returns a page

Now when I click the back button, it does not go to page-1 instead it comes with a "Confirm form resubmission" window.

How do I prevent this? Based on this answer, I see this as a recommended approach:

This is a common technique on forums. Form on Page1 posts the data to Page2, Page2 processes the data and does what needs to be done, and then it does a HTTP redirect on itself. This way the last "action" the browser remembers is a simple GET on page2, so the form is not being resubmitted upon F5.

But I'm confused. Where should I append my redirects? My page2 view looks like this:

@app.route('/StartPage',method='POST')
def test():
    username = request.forms.get('username')
    password = request.forms.get('password')
    return template('StartPage',search_string=search_string,\
                    username=username, \
                    session_id=ses_id)
like image 629
user1050619 Avatar asked Oct 20 '22 08:10

user1050619


1 Answers

To follow the POST-Redirect-GET pattern, your POST route shouldn't return a template.

  • If it can successfully process the form data, it should afterwards redirect to some sort of success/next page.

  • If there's a validation error, it should redirect back to the form, perhaps with the error details included in a query string.

like image 79
nkorth Avatar answered Oct 23 '22 02:10

nkorth