GithubHelp home page GithubHelp logo

django-reactify's Introduction

django-reactify

Makes it easy to use reactify with Django via reactify-server-rendering. No more Jinja templates!

Getting started

1. Set up your dev environment

In your dev environment set up Node.js and npm. Then do sudo npm install -g reactify-server-rendering-tools.

2. Update settings.py

reactify needs to create a JS file that your app will serve.

  1. Add REACTIFY_BUNDLE_PATH to settings.py. This is a path to a JS file in one of Django's STATICFILES_DIRS that reactify will create.
  2. Add REACTIFY_BUNDLE_URL to settings.py. This is STATIC_URL pointing to the bundle file specified in REACTIFY_BUNDLE_PATH.
  3. Add REACTIFY_SRC to settings.py. This will point to the root directory of your CommonJS modules.
  4. Add REACTIFY_MODULE_IDS to settings.py. This is the list of React component module IDs you want to call from Django. NOTE: this is relative to REACTIFY_SRC and must begin with ./.
  5. Add django_reactify to INSTALLED_APPS in settings.py.

3. Write your code

Run python manage.py reactify to build your JS bundles. This will watch for changes in DEBUG and will minify in prod.

Write your code using React and CommonJS modules. You can require React by doing require('React') -- for now, DO NOT npm install react-tools.

Create your Python views like this:

import django_reactify

def home(request):
    return django_reactify.render_to_response(
        'MODULE_ID',
        prop='value'
    )

NOTE: you will need to have a working PyExecJS installed for this to work.

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.