skip to Main Content

I am new to this kind of react flask setup and have followed multiple tutorials but none seems to work for me. All I want to have is get data sent from flask in react app.

My current setup looks like this for App.js.

enter image description here

I have also added "proxy":"http://localhost:5000/", in package.json

And flask page looks like this
enter image description here

and this is how my react page is showing

enter image description here

I can’t get my values get updated

3

Answers


  1. Chosen as BEST ANSWER

    enter image description here

    The issue was with having two servers and I resolved this issue by making changes in server side config which is flask by using CORS from flask_cors


  2. there is problem in your flask code , you have added only route but you have’t specified method i think ..

    from flask import Flask, jsonify, request
    # initialize our Flask application
    app= Flask(__name__)
    @app.route("/name", methods=["POST"])
    def setName():
        if request.method=='POST':
            posted_data = request.get_json()
            data = posted_data['data']
            return jsonify(str("Successfully stored  " + str(data)))
    @app.route("/message", methods=["GET"])
    def message():
        posted_data = request.get_json()
        name = posted_data['name']
        return jsonify(" Hope you are having a good time " +  name + "!!!")
    #  main thread of execution to start the server
    if __name__=='__main__':
        app.run(debug=True)
    
    Login or Signup to reply.
  3. To start debugging, I would suggest looking at your dev console under the network tab to see what request your javascript is making and also in the javascript console to see if the server is responding with any kind of error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search