Home > Web Front-end > JS Tutorial > body text

How to prevent the form page in Django from automatically submitting after refreshing

php中世界最好的语言
Release: 2018-03-16 15:22:46
Original
3226 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template