Home > front end >  Send React Form Input to Flask
Send React Form Input to Flask

Time:04-09

I am trying to send user input from a React form to a flask server when the user presses the submit button. How can I receive the form data from my Flask server and display it? Here is my javascript and python code:


class LineChart extends Component {

render() {

        return (

<form onSubmit={this.handleSubmit} method="post" >
                    <input type="text" id='startDate' />
                    <br></br>
                    <input type="text" id='endDate' />
                    <br></br>
                    <input type='submit' value='submit' />
</form>
)}
}
from flask import Flask

app = Flask(__name__)

@app.route("/acceptDates", methods=['POST'])
def get_dates():
#how do i implement this method


@app.route('/')
def index():
    return "<h1 > Home Page </hi>"

if __name__ == '__main__':
    app.run(debug = True)

CodePudding user response:

from flask import Flask, request

app = Flask(__name__)

@app.route("/acceptDates", methods=['POST'])
def get_dates():
    #Try this code
    startDate = request.form.get('startDate')
    endDate = request.form.get('endDate')

@app.route('/')
def index():
    return "<h1 > Home Page </hi>"

if __name__ == '__main__':
    app.run(debug = True)

Please check this answers. Click Here

  • Related