10 ms·
Django React/Redux Base Project
- sheer_horror 10y agoThey include scripts to check code quality. Perhaps those should be set up with a pre-commit git hook to ensure they get used.
- morenoh149 10y agoIs there a way to set a pre commit git hook in a project's source code? So that the same hook only runs on that project and not on every project using git.
- ecesena 10y agoTypically you add files with the scripts and a Malefile or anything similar to initialize and move those files around. So installation instructions become: 1. git clone 2. cd 3. make [init]
- wahnfrieden 10y agoNote that it works best to have that install script create symbolic links for the git hooks rather than copy, so that they can be updated without having to rerun the install script.
- chowes 10y agoWhen working with a large (read: quantity of models) REST API, is there a parallel Redux pattern to Ember's ember-data?
- acemarke 10y agoCan you clarify the question and your use case?
- shamsalmon 10y agoI think I understand what you mean... but basically your data with get put in a store and you access it in your component. Its similar to ember-data its just doing less behind the scenes. For example you do an action, fetch, then reduce, then store your data in immutable objects. In ember this is all done for you so its more code.
- morgante 10y agoThis looks a lot more sophisticated than my starter pack for the same stack, though it would be a good idea to add a Dockerfile. [0] [0] https://github.com/gigster-eng/python-starter https://github.com/gigster-eng/python-starter
- lfrodrigues 10y agohey, I'm one of the developers of this repo. We actually use docker in some of our projects but we never had time to add it to this project. Feel free to send us a PR :)
- deleted 10y ago[deleted]
- TheDrizzle43 10y agoDjango + 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.
- nsomaru 10y agois there a better way to get server side rendering rather than a whole dependency on node for a django project?
- ecesena 10y agoIf 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 https://github.com/hasgluten/hasgluten
- nsomaru 10y agoThat'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.
- hiram112 10y ago
- mozumder 10y agoSo, I made a Django site with a VanillaJS single-page app framework (no React/Redux) and that includes Django server-rendered fastboot, in about 10KB Javascript code. I made it/use it for our fashion site - https://www.futureclaw.com https://www.futureclaw.com Page load times are about .5 seconds for me, with lots of graphics. Also, I'm pretty sure it's faster than React. Is this something people want to use that I should package up into its own product? It's a little bit of code but mostly methodology discipline.
- JustSomeNobody 10y agoI wouldn't mind taking a look. I prefer VanillaJS. I'm currently using .Net/Java/C++ (yeah...) and am wanting to get away from that and switch to Python full time. So, I have been looking at as much Python code as I can lately.
- mozumder 10y agoI haven't documented/posted the JS code anywhere yet, but I did post some of the python server code on the Django developer mailing list at: https://groups.google.com/forum/#!topic/django-developers/q-5cnzlcf9k https://groups.google.com/forum/#!topic/django-developers/q-... The JS code is still being changed around. The key here to maintain state consistency between front-end and back-end is that I transfer state from client to server via "data-model" HTML attributes. These attributes also guides the router.
- JustSomeNobody 10y agoThanks. I'll go check that out when I get a break.
- andybak 10y agoIt's always interesting to see how someone elses tackles something. Personally I'd probably have used Pjax or intercooler.js for that. I assume the ajax-ey part is simply to avoid full page reloads and improve the general speed? Other than that it's fairly static content? (would be interesting to compare the performance of this vs static site generator output on a really fast CDN - my hunch would be that this would probably win unless you were at a geographic disadvantage)
- beeskneecaps 10y agoWish there was a project that setup Django along with create-react-app so that the webpack code could stay up to date with some kind of standard (avoiding eject if possible).
- misiti3780 10y agoit's actually pretty annoying in my experience to use the create-react-app with django because of CORS related issues. chrome doesnt like sending ajax requests from localhost:3000 -> localhost:8000
- memonkey 10y agoI actually work in a Flask + AngularJS stack and have been dying to learn Django + React. Flask has been incredibly easy to setup and create APIs and even though the front-end continues to have its little intricacies, it can't heart to traverse them through new technologies.
- gitaarik 10y agoSo 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-be46360cf367#.8eaaozi87 https://medium.com/@dan_abramov/you-might-not-need-redux-be4... [1] https://github.com/mobxjs/mobx https://github.com/mobxjs/mobx
- ng12 10y agoCorrect 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}) => <li> <input type="checkbox" checked={todo.finished} onClick={() => todo.finished = !todo.finished} />{todo.title} </li> ) 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?
- cheapsteak 10y agoYou can easily maintain the abstraction of dumb components if you wish to: const TodoView = ({title, isFinished, onClick}) => ( <li> <input type="checkbox" checked={isFinished} onClick={onClick} />{title} </li> ) const TodoViewContainer = observer({todo} => ( <TodoView title={todo.title} isFinished={todo.finished} onClick={() => todo.finished = !todo.finished} /> )) But how often are you changing your app's data layer? Is the tradeoff _always_ worth it? Mobx allows you to be as pragmatic or dogmatic as you choose to be
- ng12 10y ago> But how often are you changing your app's data layer? Is the tradeoff _always_ worth it? Yes, because in my mind that's the litmus test that your app is properly data-agnostic. And a key thing about Redux is it stays that way -- it's actually difficult to leak your data store to child components. Even if I adopt the above approach with MobX it'd be incredibly easy for some other developer to start passing around stores everywhere. My gut feeling is that MobX would be great for a personal project but doesn't scale that well.
- herge 10y agoAnyone have any success/tips using webpack with django collectstatic?
- bendavis381 10y agoYeah, it's no different to any other setup. Just have webpack dump the assets into a static folder somewhere ready for collectstatic.
- herge 10y agoWhat about during deployments? You run webpack on the server before running collectstatic?
- misiti3780 10y agoi do this, i just dump assets (uncompressed) into a build directory and use django pipeline for deployment. works fine for me. if you want to see it in action look here: https://github.com/josephmisiti/generic-django-project https://github.com/josephmisiti/generic-django-project
- steffenmllr 10y agoI use https://github.com/owais/django-webpack-loader https://github.com/owais/django-webpack-loader together with https://www.npmjs.com/package/webpack-bundle-tracker https://www.npmjs.com/package/webpack-bundle-tracker to handle (hashed) file loading from webpack
- civilian 10y ago+1, it's the best way to roll.
- projektir 10y agoThis seems to be expecting a Linux distribution with APT: > apt-get install -y build-essential libssl-dev libffi-dev libpq-dev python3-dev python-dev
- robohamburger 10y agoI 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?
- bmelton 10y agoToken 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.
- lfrodrigues 10y agoToken based auth doesn't need to be stateless. In fact in our current implementation it is not. If you use stateless like JWT (we had this before) you end up having a huge problem: imagine a user wants to logout all the open accounts in different browsers. How would you handle that? You would need to wait for the expiration of the token, a solution that is not that secure.
- smashed 10y agoOne solution is to store the token in localStorage, which supports events. You can listen for localStorage changes in all your tabs. When it changes, force a page reload or similar. Edit: typos
- lfrodrigues 10y agoI think you didn't understand the issue. Imagine you want to implement a "logout from all my sessions" like Facebook or Google have (sessions in different devices)
- blamarvt 10y agoAre you aware of any boilerplate repos or examples that take this approach? Seemingly every example I've seen assumes Node is the backend. After thinking about it for a second this could be because I've been looking at universal/isomorphic projects but I'd imagine you should be able to do rendering in Node and still have a completely separate API project.
- rcarmo 10y ago"We build on the solders of giants." And me thinking it was a peaceful software project, without any soldering or soldiering...
- lfrodrigues 10y agoah ups. Thanks!
- antarrah 10y agoDjango and React do not share the same mantera. Django goes better with Ember. If you insist on using React/Redux, you are better off with something like Go for the backend.
- methyl 10y agoHow come you compare Django - a full-blown web development framework with Go - just a language? You should mention some Go frameworks which go well with React, I'm really curious to hear those.
- antarrah 10y agoI don't. Go is mostly used without a framework and you've to collect your libraries. React is just a view library and you've to collect your libraries. Django, on the other hand, is monolithic just like Ember. I'd pick Django/Ember any day if it weren't for React Native platforms and the ability to share things between the web and mobile versions.
- deleted 10y ago[deleted]
- bedros 10y agois there any similar django project but with vue.js instead of react. I'm not a fan of React license
- LinuxFreedom 10y agoWhy is this packing together a backend tec and a frontend tec? I assume the frontend is generated from django models and views code? Or does one have to maintain frontend code manually - no that would not make sense at all. However I can not see any hint about how the frontend code gets generated?
- lfrodrigues 10y agoHey, check section "Main Project" in out README. Should be clear enough
- kaffee 10y agoAnyone know something like this but with a golang-based backend?
- rayalez 10y agoOh, thank you so much, this will be extremely useful for me! I've been using Django for a long time, and I love it. And now, I've just started learning React/Redux. After some research I think that Django+React is the perfect combination. This project is excatly what I needed to help me get started!
- du_bing 10y agoJavascript + Python, perfect combination!