Makes it easy to use reactify
with Django via reactify-server-rendering
. No more Jinja templates!
In your dev environment set up Node.js and npm
. Then do sudo npm install -g reactify-server-rendering-tools
.
reactify
needs to create a JS file that your app will serve.
- Add
REACTIFY_BUNDLE_PATH
tosettings.py
. This is a path to a JS file in one of Django'sSTATICFILES_DIRS
thatreactify
will create. - Add
REACTIFY_BUNDLE_URL
tosettings.py
. This isSTATIC_URL
pointing to the bundle file specified inREACTIFY_BUNDLE_PATH
. - Add
REACTIFY_SRC
tosettings.py
. This will point to the root directory of your CommonJS modules. - Add
REACTIFY_MODULE_IDS
tosettings.py
. This is the list of React component module IDs you want to call from Django. NOTE: this is relative toREACTIFY_SRC
and must begin with./
. - Add
django_reactify
toINSTALLED_APPS
insettings.py
.
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.