You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-21Lines changed: 24 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,8 @@ pip install react
50
50
Basic usage
51
51
-----------
52
52
53
-
python-react provides an interface to a render server which is capable of rendering React components.
53
+
python-react provides an interface to a render server which is capable of rendering React components with data
54
+
from your python process.
54
55
55
56
Render requests should provide a path to a JS file that exports a React component. If you want to pass
56
57
data to the component, you can optionally provide a second argument that will be used as the component's
@@ -74,12 +75,12 @@ If the object is coerced to a string, it will emit the value of the `markup` att
74
75
75
76
### Setting up a render server
76
77
77
-
Render servers are typically Node.js processes which sit alongside the python process and respond to network requests.
78
+
Render servers are typically Node.js processes which sit alongside the python process and respond to network requests.
78
79
79
80
To add a render server to your project, you can refer to the [basic rendering example](examples/basic_rendering)
80
81
for a simple server that will cover most cases. The key files for the render server are:
81
-
-[server.js](examples/basic_rendering/server.js) the server's source code
82
-
-[package.json](examples/basic_rendering/package.json) the server's dependencies, installable with
82
+
-[server.js](examples/basic_rendering/server.js)- the server's source code
83
+
-[package.json](examples/basic_rendering/package.json)- the server's dependencies, installable with
83
84
[npm](http://npmjs.com)
84
85
85
86
@@ -92,10 +93,10 @@ and downsides.
92
93
-[Webpack](https://webpack.github.io) is currently the recommended build tool for frontend projects. It can
93
94
compile your files into browser-executable code and provides a variety of tools and processes which can
94
95
simplify complicated workflows.
95
-
-[Browserify](http://browserify.org/) is another popular tool, which has a lot of cross-over with webpack. It
96
+
-[Browserify](http://browserify.org/) is another popular tool and has a lot of cross-over with webpack. It
96
97
is argurably the easiest of the two to use, but it tends to lag behind webpack in certain functionalities.
97
98
98
-
For React projects, you'll find that webpack is the usual recommendation - hot module replacement,
99
+
For React projects, you'll find that webpack is the usual recommendation. Webpack's hot module replacement,
99
100
code-splitting, and a wealth of loaders are the features typically cited.
100
101
[react-hot-loader](https://github.com/gaearon/react-hot-loader) is a particularly useful tool as it allows
101
102
changes to your components to be streamed live into your browser.
@@ -111,9 +112,10 @@ Both projects can perform the same task of integrating webpack's output. django-
111
112
reason about, it aims to do one thing and do it well. python-webpack's more complex, but offers more features.
112
113
113
114
Note: older versions of this library used to provide tools for integrating React into your frontend. While
114
-
those tools tended to provide some conveniences, they also overly complicated deployments, limited the
115
-
functionalities that you could apply, and locked you in to a limited workflow which was contrary to React's
116
-
best practices. If you want to persist with the worflow previously offered, the [self-mounting components example](examples) illustrates the functionality.
115
+
they provided some conveniences they also overly complicated deployments, limited the functionalities that
116
+
you could apply, and locked you in to a workflow which was contrary to React's best practices. If you want to
117
+
persist with the worflow previously offered, the [self-mounting components example](examples) illustrates the
118
+
wiring necessary to achieve comparable functionality.
117
119
118
120
119
121
render_component
@@ -135,7 +137,7 @@ render_component(
135
137
136
138
# An optional dictionary of data that will be passed to the renderer
137
139
# and can be reused on the client-side.
138
-
data={
140
+
props={
139
141
'foo': 'bar'
140
142
},
141
143
@@ -160,19 +162,20 @@ accepts the `path`, `data`, and `to_static_markup` arguments.
160
162
Render server
161
163
-------------
162
164
163
-
Earlier versions of this library used to run the render server as a subprocess, this tended to make
164
-
development easier, but also introduced instabilities and inexplicable behaviour. To avoid these issues
165
-
python-react now relies on externally managed process.
165
+
Earlier versions of this library would run the render server as a subprocess, this tended to make development
166
+
easier, but introduced instabilities and opaque behaviour. To avoid these issues python-react now relies on
167
+
externally managed process. While managing extra processes can add more overhead initially, it avoids pain down
168
+
the track.
166
169
167
170
If you only want to run the render server in particular environments, change the `RENDER` setting to
168
-
False. When `RENDER` is False, the render server is not used, but the similar objects are returned
169
-
with the `markup` attribute as an empty string.
171
+
False. When `RENDER` is False, the render server is not used directly, but it's wrapper will return similar
172
+
objects with the `markup` attribute as an empty string.
170
173
171
174
172
175
### Usage in development
173
176
174
-
In development environments, it's often easiest to set `RENDER` to False. This ensures that the render
175
-
server will not be used, hence you only need to manage your python process.
177
+
In development environments, it can be easiest to set the `RENDER`setting to False. This ensures that the
178
+
render server will not be used, hence you only need to manage your python process.
176
179
177
180
Be aware that the render servers provided in the example and elsewhere rely on Node.js's module system
178
181
which - similarly to Python - caches all modules as soon as they are imported. If you use the render
@@ -187,14 +190,14 @@ In production environments, you should ensure that `RENDER` is set to True.
187
190
You will want to run the render server under whatever supervisor process suits your need. Depending on
188
191
your setup, you may need to change the `RENDER_URL` setting to reflect your setup.
189
192
190
-
Requests are sent to the render server as POST requests.
191
-
192
-
The render server connector that ships with python-react adds a `?hash=<SHA1>` parameter to the url. The
193
+
When the render server wrapper connects to the JS process, it adds a `?hash=<SHA1>` parameter to the url. The
193
194
hash parameter is generated from the serialized data that is sent in the request's body and is intended
194
195
for consumption by caching layers.
195
196
196
197
Depending on your load, you may want to put a reverse proxy in front of the render server. Be aware that
197
-
many reverse proxies are configured by default to **not** cache POST requests.
198
+
render server requests are sent as POST requests and many reverse proxies are configured by default to
0 commit comments