[Answered ]-How to clear form data in django

1👍

This is about the browsers behaviour. Browser shows u the page in its cache instead of calling a new page.

U may workaround this by using javascript.Unfortunately browser also dont run the javascript codes again.

But u may try :

$(window).bind("pageshow", function() {
  // Clean form values
});

by JQuery

1👍

This is a browser implementation detail. You might be able to hack your way around it with JavaScript or break the cache etc. The subject is discussed in this stackoverflow question.

However a nicer UI approach might be to use AJAX to POST a serialised version of the form. If you successfully validate and process that form in your view (inserting a new row into your resume model table etc), you could then send a JSON response which might invoke some JavaScript to clear the form fields (maybe using .reset()). The user is then free to submit another form easily if that is the requirement.

Also note it is recommended that you use a HttpResponseRedirect after a successful POST (you have a render() response at the moment). This stops the users re-submitting the form again and potentially duplicating rows in your databases etc.

Leave a comment