Hacker News new | ask | show | jobs
by TheDrizzle43 3527 days ago
Django + React is an awesome combination that I recommend taking a look at. This repo is a good starting point but you can probably get rid of half of the dependencies if you aren't working on a team of developers.

I am currently using Django + React on a personal project and took a slightly different route, no pun intended. Rather than using react router, as I never really liked client side routing, I use Django views to hydrate all the necessary props for the page and have a base template that loads the React component with the props. Since each page / component is fairly self-contained I also decided against using any Redux / Flux implementations. Furthermore, it only takes a few hours of work to get server side rendering up and running thanks to react + node.

3 comments

We also use a bootstrapping view for our single page app. It sounds like your application is multiple pages or make a request for every "page"?

The nice thing about react router and client side routing is you can have a very clean separation from your backend data model and your actual UI/website.

I would agree that react router is like a 1000 pound javascript routing gorilla.

Hi

I'm not much of a frontend guy as I concentrate on the backend, but my team is working on a new React UI and I'm thinking of something similar, possibly.

Hopefully you can detail your plan a little more.

The reason our old Angular front-end was complex was because it was firing off dozens of small rest calls to grab every bit of state - drop downs, business logic, props, etc. - every time the route changed. It was a large SPA.

I'm proposing to do something different - break up the SPA into 6 or 7 MVC pages and push as much of the state into the html / JS that is returned, then use React only to update dynamic pieces of the front-end without having to regenerate the whole page.

Is this what you're describing or am I mistaken?

Yeah you are correct.
is there a better way to get server side rendering rather than a whole dependency on node for a django project?
If your project is small enough you can scrape it and generate all pages. You need a server only in development but then you can host it statically (and for free, e.g. on github).

Check out hasgluten.com for an example, code here (pretty old version of react though): https://github.com/hasgluten/hasgluten

That's useful, thanks.

The case I was interested in is where you'd like to have Django server-side-render the first request based on url, and then have react handle the rest via react-router and apis ala django-rest-framework.

As a backend dev who got by with jquery soup and 0 frontend build tools before (use django bundling tools), even starting to approach the React ecosystem is a little daunting.

I was where you were at a few years ago, and I really don't think these type of large SPAs are appropriate for the vast majority of business / crud sites (i.e. not Google Maps, Facebook, etc.)

I work in Java / Scala world, but have been pulled into more front-end / UI work the last few years. It seems a lot of (younger) developers use the backend only as a Restful bridge to the DB.

After seeing what is Node, Angular npm, bower, grunt, etc. and now React and friends, I'm pushing my team back to the server for all business logic and using the front-end only for dynamic forms, animations, etc.

The JS tooling is just not as good as static backend frameworks, nor are the libraries. Trying to debug dozens of async calls using Chrome Dev Tools takes 10x as long as doing it on the backend, even with multiple threads.

Doesn't avoid the node dependency, but try https://github.com/airbnb/hypernova

Honestly the node dep isn't so bad. Just think of it as a template render running on another process.

On a $5/mo 512mb/20gb DO VPS, a single django application deployed with nginx, gunicorn, postgres and redis on the same box started to OOM me (nothing in application logs!) when doing something like generating a thumbnail.

Deployed some swap and once thumbnail caches are warm we're fine, but, adding node as an additional dependency just seems overkill. python-react seems like a good fit.[0]

[0] https://github.com/markfinger/python-react

edit: s/React-python/python-react/g