Live data from Hacker News

Django React/Redux Base Project

github.com

31–40 of 79 posts

Re: Django React/Redux Base Project

#31
post #17

Anyone have any success/tips using webpack with django collectstatic?

Yeah, it's no different to any other setup. Just have webpack dump the assets into a static folder somewhere ready for collectstatic.

What about during deployments? You run webpack on the server before running collectstatic?

Re: Django React/Redux Base Project

#32

So for people who think they need Redux, first read "You Might Not Need Redux" [0] by Dan Abramov himself, creator of Redux. Then also I would recommend MobX [1] over Redux, it's easier to get started and in my opinion easier and better in general. [0] https://medium.com/@dan_abramov/you-might-not-need-redux-be4... [1] https://github.com/mobxjs/mobx

Correct me if I'm misunderstanding, but one thing that worries me about MobX is that it seems leakier than Redux. Something that I really, really care about is that a well-architected React application should hardly care what the data layer is. The bulk of the application is comprised of dumb/presenter components and only the handful of container components know anything about Redux.

Things like this (from the docs) make me nervous:

  const TodoView = observer(({todo}) =>
    
         todo.finished = !todo.finished}
        />{todo.title}
    
  )
TodoView is a dumb component that operates simple data passed via props, but now it needs to know that it's an observer and presumably rely on some facet of MobX to work?

Re: Django React/Redux Base Project

#33

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 vie…

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.

Re: Django React/Redux Base Project

#34

I feel like the best way to do this is to just use cornice or DRF then use js scaffolding that is completely unaware of your backend. No need to join them at the hip like this, except maybe for the token based auth?

Token based auth is stateless, so your first assumption stands true -- no need to join them at the hip.

I've tried working with tools like Djangular and whatnot, and no matter how many times I've tried working within that ecosystem, I've always had better results, cleaner and simpler code by keeping the UI and Backend completely separate.

Re: Django React/Redux Base Project

#35
post #17

Anyone have any success/tips using webpack with django collectstatic?

I use https://github.com/owais/django-webpack-loader together with https://www.npmjs.com/package/webpack-bundle-tracker to handle (hashed) file loading from webpack

+1, it's the best way to roll.

Re: Django React/Redux Base Project

#36
post #19
post #18

Earlier quoted context omitted.

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.

Re: Django React/Redux Base Project

#37
post #18

Earlier quoted context omitted.

is there a better way to get server side rendering rather than a whole dependency on node for a django project?

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

Re: Django React/Redux Base Project

#40

So for people who think they need Redux, first read "You Might Not Need Redux" [0] by Dan Abramov himself, creator of Redux. Then also I would recommend MobX [1] over Redux, it's easier to get started and in my opinion easier and better in general. [0] https://medium.com/@dan_abramov/you-might-not-need-redux-be4... [1] https://github.com/mobxjs/mobx

Completely agree about Redux - it has a large scope of functionality that also includes a long learning curve. I started using FreezerJS [0] a while back and have loved its simplicity. To my knowledge is the simplest alternative for state management, which you can understand in the ~100 line "Example" they provide.

[0] https://github.com/arqex/freezer

Post reply on HN