Skip to main content

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.
  • Go from development to production with ease.

Features

  • custom react scripts
  • Imports from other pages (create-react-app doesn't allow that)
  • Natively use react in django.
  • Ready-to-serve production builds with the proper paths. (using --static-url option)

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!

PyPI version (tag)

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' %}
...

Remeber 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. As a temporary fix, Run react-pages uninstall once, and then pip uninstall react-pages will work.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

react-pages-0.1.4.tar.gz (134.7 kB view details)

Uploaded Source

Built Distribution

react_pages-0.1.4-py2.py3-none-any.whl (150.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file react-pages-0.1.4.tar.gz.

File metadata

  • Download URL: react-pages-0.1.4.tar.gz
  • Upload date:
  • Size: 134.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for react-pages-0.1.4.tar.gz
Algorithm Hash digest
SHA256 db3ebc290c95e1f2e2bfea3a50b6bc55d8e1672f412b8ea23e80eae82677b33f
MD5 e11a70f4bf86b4e47c5f0eaf9743c346
BLAKE2b-256 2df8d66a6f5b901970e8cdae6a81461bf78918b074b4a8c2b0181630b8dd263a

See more details on using hashes here.

File details

Details for the file react_pages-0.1.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for react_pages-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 adaf8bf468540600155c9605367407bc6380d8e7c7f79b940d7cd1a346d73c4f
MD5 cdfa849fdef285db0735f504ab61871f
BLAKE2b-256 6ca9feddcfba3502f67bb9b6fd1b13031a6b38f154f64409511fa5885d0e7b62

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page