Using React on a particular section (DIV) of a Django application

So, 99% of the Django + React tutorials are of using Django with DRF and having React as the sole stand-alone application.

My colleague referred us to this - React Django integration. Using Webpack and Webpack-Loaders with… | by Shubham Kushwaha | Analytics Vidhya | Medium - to power a section (a DIV) of our existing Django 2 application in React.

  1. I was wondering why this is not talked about much. Is there a drawback of using React on a particular section of a traditional page vs using React on the whole page ?

  2. Won’t create-react-app’s react-scripts start work here ? Does it really need to be customized for injecting a React app into an existing Django app this way ? (like writing webpack.config.js )

Maybe this blog can help you Building a SaaS Application with Django

2 Likes

I definitely recommend the series suggested above (I should as I wrote it :slight_smile: )

There’s not a major drawback to the approach once you get things up and running. I think the reason people do the standalone thing is often because they are coming from a React background and just want an API because they like building SPAs, not because it’s necessarily the best thing to do. The main issue is just getting the tooling and such sorted out, but it’s a one-time setup cost.

You do need a little bit of custom tooling beyond create react app though, because you’ll end up generating a JS bundle and then serving it statically from Django (as opposed to via node). But it’s not bad, I promise! This section of the guide may help Integrating a Modern JavaScript Pipeline into a Django Application