How to Submit a Form to the Same Page with Python in Django


In this article, we show how to submit a form to the same page with Python in Django.

Submitting a form to the same page that the form is currently on is very simple.

When you create a form there is an action attribute. If you want the form submitted to the same page that the form is on, then all you have to do is set the action attribute equal to null ("").

So below, we have a form in which the action attribute is set equal to "". Therefore, the form results, based on how you program it, stays on the same page.

Just like with PHP, as a comparison, to submit form data to the same page, you simply set the action attribute to "".

If you want to transfer the data of the form to another page, then you have to specify in the action attribute the URL path to that page.

So the action attribute is all you have to work with when deciding whether a form should stay on the same page after 'Submit' is pressed or carried somewhere else.

Related Resources

How to Randomly Select From or Shuffle a List in Python

HTML Comment Box is loading comments...