A zero-fuss way to create non single page apps with react.
Project description
React Pages
A zero-fuss way to create non single page apps with react.
- Zero Configuration required. Mostly thanks to create-react-app.
- Custom react scripts inbuilt.
- Cross-page import (create-react-app doesn't allow this).
- Ready-to-serve production builds with the proper paths. (using
--static-url
option) - Natively use react in django.
- Go from development to production with ease.
- Caches npm stuff. You'll notice that the command
react-pages project
runs much after the 1st time.
Terminology
Project
The project contains the node.js modules necessary to use react and the pages you create.
└── my_project
├── package.json
├── package-lock.json
├── .env
├── .gitignore
├── public
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
<pages>
Page:
A page is a directory containing at least an index.js
file, (and other css/js files specific to your application.)
└── my_page
├── App.css
├── App.js
├── App.test.js
├── index.css
├── index.js
├── logo.svg
└── registerServiceWorker.js
QuickStart
You need npm on your machine!
pip install react-pages
Commands :
$ react-pages project my_project # create a project
$ cd my_project # Don't forget to do this!
$ react-pages page my_page # create a page
$ react-pages develop # development
$ react-pages deploy # production
$ react-pages runserver # django runserver alternative
Django Integration
settings.py
INSTALLED_APPS = [
...
'react_pages',
...
]
# React Pages
REACT_PAGES_PROJECT_DIR = os.path.join(BASE_DIR, 'my_project') # specify the react-pages project
STATICFILES_DIRS = [
...
os.path.join(REACT_PAGES_PROJECT_DIR, 'build') # mark the build dir as static file dir
...
]
template.html
{% load react_pages %}
...
{% render_react_page 'my_page' %}
...
Remember to use react-pages runserver
instead of manage.py runserver
!
That's it! React Pages will pick-up the "my_page" page from "my_project" project and do the necessary work to transpire react JSX.
Django Context
You can pass django template context varialbes like so -
views.py
context['py_numbers'] = [1, 2, 3]
template.html
{% render_react_page 'my_page' js_numbers=py_numbers %}
Then access these anywhere in JS
console.log(js_numbers);
Note: These must be JSON serialize-able
For production, just put DEBUG=False
in settings.py
and relax.
Existing projects
React Pages will automatically patch itsef into any existing project,
that was created using create-react-app
.
Just run react-pages project .
from your project directory!
Projects not using create-react-app
will probably work,
but no guarantees can be made.
Issues
-
It might not uninstall using pip.
This is a side-effect of react-page's caching.
As a temporary fix, Runreact-pages clear-cache
, and thenpip uninstall react-pages
will work as expected.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file react-pages-0.1.5.tar.gz
.
File metadata
- Download URL: react-pages-0.1.5.tar.gz
- Upload date:
- Size: 134.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8efaf68a52d54589ebf62ed85e6e8ef032946959e65ba447cda15df69cf87ee |
|
MD5 | a76c4e48ca4ab8b06f5e8e0254cc5fde |
|
BLAKE2b-256 | 33831c7cb01d92cf0de28ceac0f98ab3dcb5dec36cd94c03b71065ed83d05e71 |
File details
Details for the file react_pages-0.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: react_pages-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 150.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 036a3696e393aa8e3b853c2438e2ebf6ee112bdb4ae46680aa3c27cd491cd8dd |
|
MD5 | 14c37be035aee04e0042adc46c57566e |
|
BLAKE2b-256 | cc6fa9e465d65abc7b6cb2d46a53ef6c9da4432eb43ee94199f03b927d8eef73 |