12

I'm familiar with Flask for building simple webapps and using jinja2 as a template engine. However, I'd like to try out React.js as a front-end.

The examples I've seen that use React.js with a Python backend essentially use it as an API server to call the json needed to include in the React views. However, how does this work with authentication models and libraries for Flask? Can you mix-and-match jinja2 and React.js within the same template, to get access to the session data?

Any pointers or experience to help get started would be appreciated.

3
  • 1
    I haven't used flask, but is there any reason you can't serialize the data as json? And no, you can't easily mix jinja2 and react, but you can do the base page in jinja2 and render parts in react. Commented Feb 4, 2015 at 7:58
  • Thanks @FakeRainBrigand - I've done some additional reading after your comment and saw some examples that used jinja2 for the base templates, and then placed the react.js code within the authorised user if-loop. That seems to be the way forward. Thanks for the pointers. Commented Feb 4, 2015 at 22:22
  • 4
    hi Phil, could you please provide details of the example you have seen that using python as a API server that interact with reactjs? e.g. where to download the repo? thanks Commented Mar 15, 2015 at 22:35

1 Answer 1

6

It is possible to use React.js within the Jinja2 template system. This is the solution, placing the React components within an authorised user if loop, using a library like Flask-Login.

Here's a further example I found of someone working this through: Flask and Reactjs throw JSX Transform error.

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.