Problem: I am attempting to process the data from a form the user enters in the React Frontend . I want to do some calculations on a variable, I am currently just want to print it out, eventually I would want to return information back to the React application, but I can't get this simple step to work.
My Attempt: This is the snippet of the form I am using:
<form className="patient-form" method="post">
<input type="text" name="variable" />
<input type="submit" />
This is the Python Backend in which I want to use the variable:
from flask import Flask,request
app = Flask(__name__)
@app.route('/',methods=['POST'])
def getVariable():
variable = request.json["variable"]
return {"variable": 'Backend variable' + variable}
I am also using a proxy in package.json in order for React and Flask to work simultaneously.
When I enter information from the form I get:
Cannot Post /. --> This is on localhost:3001
On the flask backend I get:
The method is not allowed for the requested URL.
So this would seem like I am using the wrong route, which route would I use for this to work?
I apologize if this is simple, as you can tell I am new to React and Flask.
I found this post: How to send data from React to Flask then back to react and show output on DOM
I am still not able to POST data to the flask backend from the frontend form, am I missing something simple?