This time I will show you how to prevent automatic submission after the form page in django is refreshed, and how to prevent automatic submission after the form page in django is refreshed. What are the precautions?, here is the actual combat Let’s take a look at the case.
If a page contains a form, and the submit button in the form is an input of type=submit, and you refresh the page, there will be a pop-up window prompting whether to resubmit the form. , this feature is very annoying, there are two common solutions:
The first is the front-end solution:
Change input[type=submit] to button.onclick (function(){ajax;}) to submit the form asynchronously, this method will not cause pop-up problems of the form.
The second is the back-end solution:
Change the return code after form.is_valid() from TemplateResponse to HttpResponeRedirect(url). This method will not return the previous form, but returns a new form page. It also perfectly avoids the problem of refreshing form pop-ups.
Based on the current development progress of assetlibrary, I plan to adopt the second solution, so that the goal can be achieved with minimal modifications. Now considering that the development needs to be rushed, the code is reused in many places, so the current form is semi-asynchronous. Even if the form submission is fully asynchronously processed in the future, I have reserved the interface toupdate .
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!
Recommended reading:
How to implement horizontal scrolling and floating navigation in js
Development of Nodejs views and models
The above is the detailed content of How to prevent the form page in Django from automatically submitting after refreshing. For more information, please follow other related articles on the PHP Chinese website!