Home > Net >  Why is my flask sqlite program throwing 404?
Why is my flask sqlite program throwing 404?

Time:05-17

I am trying to insert values from an HTML form into my sqlite3 database. However, I am facing a 404 issue when I click the submit button on the form. It does not save anything in the database and does not render the second HTML page.

The following link contains the code for the app.py server code: https://pastebin.com/h4616M0G

Following is the error message I received:

* Running on http://127.0.0.1:5000/ (Press CTRL C to quit)
127.0.0.1 - - [17/May/2022 16:10:40] "GET /home2.html?name=John&[email protected]&phone=93429348&password=sjhdbvjs HTTP/1.1" 404 -

CodePudding user response:

There is no route for /home2.html in your Python code. You defined /registerCustomer, so you must change your form action to this one or change your route.

CodePudding user response:

The log shows a GET request to the website. This means that the browser sends a GET request instead of a POST request.

The http-parameters containing the form values hint in the direction that in the html source of the website the form element is missing the method="POST" attribute.

The 404-error appeares when a flask route doesn't exist. The route /home2.hmtl doesn't exist as the route in the app is /registerCustomer.

To fix this issue add the method="POST" attribute and the correct url:

<form action="/registerCustomer" method="post">
  ...
</form>
  • Related