Entonces tengo la ruta api aquí donde podemos agregar un usuario a mi servidor
@app.route('/api/adduser', methods = ['POST']) # This is a post method because the user needs to be able to add info def adding_stuff(): request_data = request.get_json() # Gets the info from the table and converts to JSON format new_fname = request_data['firstname'] new_lname = request_data['lastname'] conn = create_connection("", "", "", "") sql = "INSERT INTO restaurantusers (firstname, lastname) VALUES ('%s', '%s');" % (new_fname, new_lname) # This sql statement will then be uploaded to the databse to add a new record execute_query(conn, sql) # This will execute the query return 'Post worked'Luego tengo un servidor NodeJs ejecutándose con la API que se selecciona cuando se completa el formulario
app.post('/add_people', function(req, res){ axios.get('http://127.0.0.1:5000/api/adduser') .then((response)=>{ var restlist = response.data.results; console.log(restlist); // Now we will execute the results in the page named thanks }); });Por último, el formulario se ve así
<form action="/add_user" method="post"> <input type = "text" firstname = "firstname"> <input type="submit" class="btn btn-primary"> <h1>Lets add our last name </h1> <form action="/add_user" method="post"> <input type = "text" lastname = "lastname"> <input type="submit" class="btn btn-primary"> </form>¿Qué falta o qué puedo agregar para que el usuario realmente se agregue al servidor?