0

I am working with this flask react template project here and I am running into an issue

https://github.com/bonniee/react-flask

When rendering index.html, I want to pass back some data from flask

@app.route('/')
def hello_world():
  return render_template('index.html', somedata="YOOOO")

And use it in the react components

render() {
    this.loadDataFromServer();

    return <h1>sup? {{somedata}}</h1>;
  }
});

Is there a clean way to do it in this project format?

1 Answer 1

1

In your template, you could include a script tag that sets window.somedata to the value you want. You could then access that directly in render, or preferably if you've got flux or redux you could dispatch an action with that data during mounting of the react components.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.