-1

I havea form in the React front end as follows :

export function Services() {
    return (
    <div>
        <form action="http://127.0.0.1:5000/">
            <label for="stock">stock</label>
            <input type="text" id="stock" name="stock" />
            </form>
      
            <h2>Services </h2>
    </div>
    );
}

I need to send the data to my flask app at the given port. The code there is :

from flask import Flask, request
app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def hello_world():
    if request.method == 'POST':
        stock = request.form('stock')
        return stock
    else:
        return "Post request was not made"

Everytime i run this, it says post request was not made. What mistake am i doing and how should i proceed to connect the react frontend to flask backend.

GodOfWar
  • 1
  • 1

1 Answers1

0

The default method for the <form> tag is GET. To change it to POST:

export function Services() {
  return (
    <div>
      <form action="http://127.0.0.1:5000/" method="post">
        <!-- ... -->
      </form>
    </div>
  );
}
steveluscher
  • 4,144
  • 24
  • 42