将 React 表单输入发送到 Flask

Send React Form Input to Flask

我正在尝试在用户按下提交按钮时将用户输入从 React 表单发送到 Flask 服务器。如何从我的 Flask 服务器接收表单数据并显示它?这是我的 javascript 和 python 代码:


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)
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)

请检查这个答案。 Click Here