Search code examples
reactjsflaskweb-applications

How to use Flask to serve a React.js single page component


I have an application that is largely tables and standard pages and forms. However, I have one page this really need to be highly responsive that is probably best developed in React.js.

I would like to have a Flask + Jinja handle the delivery of most of the pages. I understand Facebook does a bit of this with PhP for the majority of the site with React.js handing the responsive components. Is there a Flask library that makes this simple?


Solution

  • I don't think you need to use any library for this as it's pretty straightforward.

    All you need to do is:

    • Make that page using React.js and build the project to make bundle Javascript file which bootstraps the React.js page.
    • Make div inside your jinja template and import that bundle javascript file.

    Here, one important thing is to assign identical 'id' to the Jinja template div and React.js rendering div.