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
replace the app with your application directory.
Django Usage
$ python -m PyCRA --mode=django --app_name=name
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_cra-0.0.1.tar.gz.
File metadata
- Download URL: py_cra-0.0.1.tar.gz
- Upload date:
- Size: 7.1 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc2d392b54aacdb68d18368031aca11d9aeeb816118c93e2de3569cd8bf41c35
|
|
| MD5 |
f61278959034ab748b43b5d163f62591
|
|
| BLAKE2b-256 |
b2a77a00f0f5e4029036bc3d5ccac6a62a713d267df282e024b84cc9033c007e
|
File details
Details for the file py_cra-0.0.1-py3-none-any.whl.
File metadata
- Download URL: py_cra-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d72f88ce960b3811d05b674daa3774b593704a4ede2f6be573ae6776638eae1
|
|
| MD5 |
4a7f84c27dd8f5e3152a957572a285fd
|
|
| BLAKE2b-256 |
aecf4e6f4042b88cc7a1dab2ddb8a7d5aca1e35031e8ed0feae43a99225dc599
|