@@ -54,7 +54,7 @@ python-react provides an interface to a render server which is capable of render
54
54
from your python process.
55
55
56
56
Render requests should provide a path to a JS file that exports a React component. If you want to pass
57
- data to the component, you can optionally provide a second argument that will be used as the component's
57
+ data to the component, you can optionally provide a second argument that will be used as the component's
58
58
` props ` property.
59
59
60
60
``` python
@@ -77,10 +77,10 @@ If the object is coerced to a string, it will emit the value of the `markup` att
77
77
78
78
Render servers are typically Node.js processes which sit alongside the python process and respond to network requests.
79
79
80
- To add a render server to your project, you can refer to the [ basic rendering example] ( examples/basic_rendering )
81
- for a simple server that will cover most cases. The key files for the render server are:
80
+ To add a render server to your project, you can refer to the [ basic rendering example] ( examples/basic_rendering )
81
+ for a simple server that will cover most cases. The key files for the render server are:
82
82
- [ render_server.js] ( examples/basic_rendering/render_server.js ) - the server's source code
83
- - [ package.json] ( examples/basic_rendering/package.json ) - the server's dependencies, installable with
83
+ - [ package.json] ( examples/basic_rendering/package.json ) - the server's dependencies, installable with
84
84
[ npm] ( http://npmjs.com )
85
85
86
86
@@ -92,13 +92,13 @@ setup involves a build tool and a python package that can integrate it.
92
92
93
93
The two most popular build tools are:
94
94
95
- - [ Webpack] ( https://webpack.github.io ) - compiles your files into browser-executable code and provides a
95
+ - [ Webpack] ( https://webpack.github.io ) - compiles your files into browser-executable code and provides a
96
96
variety of tools and processes which can simplify complicated workflows.
97
- - [ Browserify] ( http://browserify.org/ ) - has a lot of cross-over with webpack. Is argurably the easiest of the
97
+ - [ Browserify] ( http://browserify.org/ ) - has a lot of cross-over with webpack. Is argurably the easiest of the
98
98
two to use, but it tends to lag behind webpack in functionality.
99
99
100
- For React projects, you'll find that webpack is the usual recommendation. Webpack's hot module replacement,
101
- code-splitting, and a wealth of loaders are the features typically cited as being irreplaceable.
100
+ For React projects, you'll find that webpack is the usual recommendation. Webpack's hot module replacement,
101
+ code-splitting, and a wealth of loaders are the features typically cited as being irreplaceable.
102
102
[ react-hot-loader] ( https://github.com/gaearon/react-hot-loader ) is a particularly useful tool, as it allows
103
103
changes to your components to be streamed live into your browser.
104
104
@@ -121,8 +121,8 @@ javascript worlds.
121
121
render_component
122
122
----------------
123
123
124
- Renders a component to its initial HTML. You can use this method to generate HTML on the server
125
- and send the markup down on the initial request for faster page loads and to allow search engines
124
+ Renders a component to its initial HTML. You can use this method to generate HTML on the server
125
+ and send the markup down on the initial request for faster page loads and to allow search engines
126
126
to crawl your pages for SEO purposes.
127
127
128
128
@@ -147,6 +147,12 @@ render_component(
147
147
148
148
# An optional object which will be used instead of the default renderer
149
149
renderer = None ,
150
+
151
+ # An optional dictionary of request header information (such as `Accept-Language`)
152
+ # to pass along with the request to the render server
153
+ request_headers = {
154
+ ' Accept-Language' : ' da, en-gb;q=0.8, en;q=0.7'
155
+ },
150
156
)
151
157
```
152
158
@@ -156,25 +162,25 @@ via Django's static file finders.
156
162
By default, render_component relies on access to a render server that exposes an endpoint compatible
157
163
with [ react-render's API] ( https://github.com/markfinger/react-render ) . If you want to use a different
158
164
renderer, pass in an object as the ` renderer ` arg. The object should expose a ` render ` method which
159
- accepts the ` path ` , ` data ` , and ` to_static_markup ` arguments.
165
+ accepts the ` path ` , ` data ` , ` to_static_markup ` , and ` request_headers ` arguments.
160
166
161
167
162
168
Render server
163
169
-------------
164
170
165
171
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
172
+ easier, but introduced instabilities and opaque behaviour. To avoid these issues python-react now relies on
167
173
externally managed process. While managing extra processes can add more overhead initially, it avoids pain down
168
174
the track.
169
175
170
176
If you only want to run the render server in particular environments, change the ` RENDER ` setting to
171
- False. When ` RENDER ` is False, the render server is not used directly, but it's wrapper will return similar
177
+ False. When ` RENDER ` is False, the render server is not used directly, but it's wrapper will return similar
172
178
objects with the ` markup ` attribute as an empty string.
173
179
174
180
175
181
### Usage in development
176
182
177
- In development environments, it can be easiest to set the ` RENDER ` setting to False. This ensures that the
183
+ In development environments, it can be easiest to set the ` RENDER ` setting to False. This ensures that the
178
184
render server will not be used, hence you only need to manage your python process.
179
185
180
186
Be aware that the render servers provided in the examples and elsewhere rely on Node.js's module system
0 commit comments