Skip to main content

Django-React Packager

React-Django packager helps you ship a react front end with django as backend. This package automatically builds your react project and places the static and index file in their appropriate place in your django project.

Installation

Install the package using pip:

pip install dr_packager

and thats it!

Motivation

React is one of the most popular front-end frameworks, and with django being one of the most popular backend choices, there are a lot of websites built with this stack. You can serve django on a different server than the react project and communicate between them using an API, but for smaller projects (or even bigger ones), Having 2 separate server is not justified. Copying react build files to your server is not fun either (which can be simplified with a CI\CD).

This project helps you serve react project with django (that can be deployed on a single server). This package was made out of frustration of building react project and manually copying everything to django project.

Usage

To use the packager, you should have both the react folder & django folder in the same parent folder as follows (Absolute path is still not supported in this version):

├───root_folder
│   ├───django_project
│   ├───react_project

Your django project should contain:

  • An app that serves the index.html
  • A static folder (set by STATIC_ROOT variable in your settings)

IMPORTANT: Your django project root folder and base app should have the same name for example, settings.py should be located at example.example.settings.py

Open terminal in root_folder, and run the following command:

dr_package <react_path> <django_path> <django_front_app_name>

Following the above folder example, consider that we have an app named front in our django project:

dr_package react_project django_project front

IMPORTANT: Your django settings files should contain STATIC_ROOT variable

Commands

usage: dr_package [-h] [-S] [--npm] [--yarn] [-D] [-I] [--folders-old [FOLDERS_OLD ...]]
                  react_path django_path app_name

Build React Project and Deploy with Django!

positional arguments:
  react_path            React folder name (RELATIVE PATH)
  django_path           Django folder name (RELATIVE PATH)
  app_name              Name of the app that holds index.html

optional arguments:
  -h, --help            show this help message and exit
  -S, --skip-build      Skip react build (Use what is alredy in \build\)
  --npm                 use npm as the package manager of the react project
  --yarn                use yarn as the package manager of the react project
  -D, --delete-old      Delete old static files
  -I, --install         Run install command before building (use if you haven't installed the required packages)
  --folders-old [FOLDERS_OLD ...]
                        Name of the folders to delete (Doesn't work if --delelete-old is not provided), separated by
                        space

Roadmap

  • Support for absolute path
  • Default setting file
  • More customization
  • Creating a separate django package (to run as management commands) to use with git hooks

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Metadata

Release files for dr-packager 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dr-packager 0.1.0
File Size Uploaded
dr_packager-0.1.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dr-packager 0.1.0
File Interpreter ABI Platform
dr_packager-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / dr_packager-0.1.0.tar.gz

Download URL dr_packager-0.1.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
59c56700a61e3e561a81c870ea05e0319e60c58d9e4d1d6d0c2147191e14ae10
BLAKE2b-256 checksum
How to use checksums
0f3da55201744ed92026668e4c0198fb1bcf35fc20b06de7e1935eecc9c7efbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.2 Windows/10

Release files / dr_packager-0.1.0-py3-none-any.whl

Download URL dr_packager-0.1.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9653845e456e1775ce062634f76f8261a21c4d0784bad9ad968c9d8acf6e19d7
BLAKE2b-256 checksum
How to use checksums
97f522b8bc74d7c94401709b549a565b19822b84b329b2be7003d8f6f7d98f17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.2 Windows/10

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page