This library supports two SSR services, Hypernova and Hastur.
(We assume you got a working Hypernova SSR service running). To use hypernova you need to do the following:
- Install
django_react_templatetags
with thehypernova
flag.
pip install django_react_templatetags[hypernova]
- Change SSR Service to hypernova (by adding this django setting)
REACT_SSR_SERVICE="django_react_templatetags.ssr.hypernova.HypernovaService"
- Make sure your
REACT_RENDER_HOST
points to the batch endpoint
REACT_RENDER_HOST='http://react-service.test/batch
- Django React Polls with Hypernova examples covers two ways of implementing Hypernova in Django and DRTT.
To use django-react-templatetags with Hastur you need to do the following:
- Install
django_react_templatetags
with thessr
flag.
pip install django_react_templatetags[ssr]
- Point the right endpoint:
REACT_RENDER_HOST='http://hastur-service.test/
It works by posting component name and props to endpoint, that returns the html rendition. Payload example:
{
"componentName": "MyComponent",
"props": {
"title": "my props title",
"anyProp": "another prop"
},
"context": {"location": "http://localhost"},
"static": false
}
You can set the context-parameter by using the ssr_context
property on the template tag:
{% react_render component="Component" ssr_context=ctx %}