Django-React-Views
django-react-riews is a Django app providing generic Class Based views and template tags that make it easy to use react alongside django views and templates.
It can be used along with channels-redux-python and channels-redux-js to provide a framework to use websockets to keep a frontend redux state in sync with the database state.
Quick start
-
Add "django_react_views" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [ ... 'django_react_views', ]
-
Create a directory in your app called
react -
Copy
webpack.config.jsor use you're own webpack config as long as it builds your react components into one of your STATICFILES_DIRS -
Use npm to install at least the packages required for react & building with webpack
npm install --save-prod react react-dom npm install --save-dev babel-core babel-loader babel-preset-env babel-preset-es2015 babel-preset-react glob webpack webpack-cli
-
Add these scripts to
package.json"scripts": { "build": "webpack", "watch": "webpack --watch" },
-
Execute
npm run watchto start building your react files -
Add the react template tag to the template where you want to show your react component
{% load react %} ... {% react %} ... -
Create a view for your template
from django_react_views.views import ReactDetailView class MyReactView(ReactDetailView): react_component = 'MyReactComponent.js' # By default this will resolve to dist/app_name/{react_component}. If {% static %} can not find the file you may need to edit some other properties of this class model_serializer = MyModelSerializer model = MyModel
-
Add a url for your view
urlpatterns = [ ... path('my-react-view/<int:pk>/', MyReactView.as_view(), name='my-react-view') ]
-
This framework provides window.props, which contains a javascript object that can be used to hydrate your react state. This has the shape of::
window.props = {"objects": {"appname.modelname": {"https://example.com/appname/modelname/1/": {object as serialized by your model serializer}} } }
-
Start the development server and visit http://127.0.0.1:8000/ and visit your page to see you're react component in action
Metadata
Release files for django-react-views 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-react-views-1.1.tar.gz | 5.5 kB | Without provenance | Details for django-react-views-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_react_views-1.1-py3-none-any.whl | Python 3 | none | any | Details for django_react_views-1.1-py3-none-any.whl |
Total release size: 11.8 kB
Release files / django-react-views-1.1.tar.gz
| Download URL | django-react-views-1.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01049d1c445609db3c14ba31186b07be10c33eb258aada4e86059b4bc1c901bb
|
|
BLAKE2b-256 checksum How to use checksums |
499e7515fc88a355ca0e2367aed00963b1b5d6043bdd91f8c82b97c100fdb79a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_react_views-1.1-py3-none-any.whl
| Download URL | django_react_views-1.1-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5affb38e325e00c1956181198481a610546bb8dcfab0af5eb8e09eff056d1609
|
|
BLAKE2b-256 checksum How to use checksums |
e9c63f9359ccdb91b1ebd7ed3b0cce40a22540eaead36e9094f366767acd6225
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-react-views 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.