Code Monkey home page Code Monkey logo

drf-react-redux's Introduction

Redux DevTools + Django todomvc example

This repository shows how to use Django, Django Rest Framework, React, and Redux together. It also utilizes hot reloading via webpack and redux dev tools to enable time traveling state.

That said, it's a little slapped together. It all works, but this ain't production level code. But feel free to use this to get a feel of how you can fit these things together.

Also, this is based off of Dan Abromov's todomvc example in https://github.com/gaearon/redux-devtools. You can find that here:

https://github.com/gaearon/redux-devtools/tree/master/examples/todomvc

Running Example

First, clone the project:

git clone https://github.com/bigsassy/drf-react-redux.git && cd drf-react-redux

Next, create a virtualenv for your repository:

virtualenv env && source env/bin/activate && pip install -r requirements.txt

Now go into the Django project directory.

cd todomvc

This is our django project, which was created with django-admin startproject by myself when creating this example repository. I've changed a few things after running that command:

  • I've created a folder called server to store all apps created using ./manage.py startapp. Right now it has the initial todomvc app created by django-admin startproject as well as another app called todo that was generated by ./manage.py startapp todo.
  • I've created a folder called client to store all of our React javascript code. It's called client because this code will be ran on the client (i.e. the browser), as opposed to the Django code which will be ran on the server (thus that folder being called server).
  • There's some new files in the same directory as manage.py that's used to manage our javascript code.
    • .babelrc tells babel how to compile our JSX and ES2015 (i.e. ES6) code into javascript that's readable by today's browsers.
    • package.json is used to manage our node_modules directory (think virtualenv for javascript), as well as provide a custom command to run our webpack server that handles hot reloading, which is ran by npm start (kinda like ./manage.py runserver).
    • server.js is our webpack dev server, used for serving our javascript in a way that allows it to be hot reloaded. When you run npm start it actually just calls node server.js to run this server.
    • webpack.config.js is the configuration file for the webpack server. It tells webpack where to find our React javascript code and then how to transpile it and all it's dependencies.
    • webpack-stats.json is a file that'll be generated when you run this example project. It's created by the django-webpack-loader library and tells it how to let our Django templates point to the webpack dev server, allowing hot reloading in your app running from Django's web server.

Anyway, now go ahead and install the javascript dependencies in the root folder:

npm install

Then create the database for the Django project, and create a super user:

./manage.py migrate && ./manage.py createsuperuser

Now open this directory in a second terminal, and turn on your virtualenv by running source ../env/bin/activate. Run the first command in one terminal, and the second command in the other terminal:

npm start
./manage.py runserver

Finally, login to your site via the admin: http://localhost:8000/admin

After you're logged in, you'll be able to use the Todo app and browse the API:

drf-react-redux's People

Contributors

ericpalakovichcarr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drf-react-redux's Issues

npm start gives the following error

ERROR in ./client/index.js
Module build failed: SyntaxError: Unexpected token (10:2)

   8 |
   9 | render(
> 10 |   <Root store={store} />,
     |   ^
  11 |   document.getElementById('root')
  12 | );
  13 |

Tutorial

Not an issue, but a suggestion as I really like the setup you have put together. Have you considered providing a tutorial on the steps to setup the django side of things ?

Thanks for the sample!

Hey โ€“ not an "issue," just a compliment ...

Of the various "illustrations of how to use these tools together" that are available here, I just wanted to say that this is a particularly nicely-done and complete one. (Starred ...) It's very representative of such applications and of good practices, in a very small space. (And maybe, it's the first darned .md file I've run into around these parts that actually tells you something!) :-D

Thanks for sharing!

Production Environment

How can I use this on the production env without HMR so as to avoid having a separate Node server? Just reconf of webpack to just bundle static js?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.