Skip to main content

Python tool to create an react web app for django or flask backend

Project description

Python Create React App

PyCRA is a tool used to create a react frontend app for a backend server usually Flask or Django backend.

the tool works a that, it creates a couple of dirs and files in a certain directory. init a npm package.json in the directory. and with the babel it compile the react app into static/js/main.py. and then it loaded into the templates/*/index.html then this html file is rendered by the flask or django backend server.

Install

$ pip install py_cra

Requirements

- npm
- nodejs
- git
- python>=3.6

Usage

$ python -m PyCRA

Flask Usage

$ python -m PyCRA --mode=flask --app_dir=app

Here your have two options

  • either you execute this command from outside your app directory like
    • ./
    • ../
    • app/
    • $ python -m PyCRA --mode=flask --app_dir=app
  • or fron inside your app directory like.
    • ./
    • ../
    • run.py
    • $ python -m PyCRA --mode=flask --app_dir=.

replace the app with your application directory.

Django Usage

$ python -m PyCRA --mode=django --app_name=name

Here you must be in your BASE_DIR or the directory where the manage.py lives. this is important so your application did not get messed up. Make sure that you have create the django app first before you execute the command.

replace the name with your django app name

Help

$ python -m PyCRA --help
usage: __main__.py [-h] [--mode MODE] [--app_name APP_NAME] [--app_dir APP_DIR]

optional arguments:
  -h, --help           show this help message and exit
  --mode MODE          django or flask mode
  --app_name APP_NAME  app name if django mode
  --app_dir APP_DIR    app dir if flask mode

Post Creation

After that you need to run this command

$ npm run dev

to compile your js source files and create the main.jsthat get loaded into the index.html and load the app into your browser. make sure that the $ npm run dev run and remain watching any changes into your files. it recompile every this once any change is happened to the js source files. finally to build the app you shoud use the.

$ npm run build

to finally compile your app.

Django

In case of django backend add a view into the frontend/views.py. In here we use the frontend name as the django app.

from django.shortcuts import render

def index(request):
	return render(request=request, template_name='frontend/index.html')

Flask

In case of flask backend add a route to the app.py

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
	return render_template('index.html')

if __name__ == '__main__':
	app.run(debug=True)

Info

please, make sure that this is only works a frontend app only. so you cannot use something like jinja templating instead you should create a rest api as your backend server that can be created with eiher flask_restful in case of Flask or django-restframework in case of Django.

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

py_cra-0.0.6.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_cra-0.0.6-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file py_cra-0.0.6.tar.gz.

File metadata

  • Download URL: py_cra-0.0.6.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for py_cra-0.0.6.tar.gz
Algorithm Hash digest
SHA256 a93b9039edbffd0c74d84bd9330c20409fda5ebd95a554f71cf301766f7f1e20
MD5 c5573739a4b6329b93e59a31bcde76b4
BLAKE2b-256 a13da2e91b10c07c043dab6731dc02f7d7159b59b2f8289cf7a9c3984e763edc

See more details on using hashes here.

File details

Details for the file py_cra-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: py_cra-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for py_cra-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 260460108a10eeecf48db3f1e862cccb28e9d523236351eee252c9f0b7ab391e
MD5 d11aff5e225191244e31fd05a9d90402
BLAKE2b-256 093bfd83d5ffc6386d02e3c96e49169b161c476331c545a3e6c8ea7182bd1e6b

See more details on using hashes here.

Supported by

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