Flask form submission without Page Reload
There are many modules or frameworks which allows to build your webpage using python like bottle, django, flask etc. But the real popular ones are Flask and Django. Django is easy to use as compared to Flask but Flask provides you the versatility to program with.
If we do post request then the whole page will reload. So this article revolves around how to send the form data to flask backend without reloading the page. For submitting form without reloading page we use jquery and ajax. So before using flask we have to install that
pip3 install flask
Create new directory for your project. Inside that create new file and name it as app.py
Then create new directory and name it as templates
Inside that create new file and name it as home.html
- e.preventDefault() :- This function doesn’t reload the page
- type: GET or POST request
- url : url that we have specify in our flask app
- data : Form data that we want to pass
- Succes: function() :- This function run after successfully submitting the values and when there are no error occur while submitting the data.
On the cmd or terminal it will print the value we have submitted using form.
Please Login to comment...