django-reactify
django-reactify copied to clipboard
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.
- Add
REACTIFY_BUNDLE_PATHtosettings.py. This is a path to a JS file in one of Django'sSTATICFILES_DIRSthatreactifywill create. - Add
REACTIFY_BUNDLE_URLtosettings.py. This isSTATIC_URLpointing to the bundle file specified inREACTIFY_BUNDLE_PATH. - Add
REACTIFY_SRCtosettings.py. This will point to the root directory of your CommonJS modules. - Add
REACTIFY_MODULE_IDStosettings.py. This is the list of React component module IDs you want to call from Django. NOTE: this is relative toREACTIFY_SRCand must begin with./. - Add
django_reactifytoINSTALLED_APPSinsettings.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.