Skip to main content

React extension for Flask

Project description

Flask-React

React extension for Flask applications with support for multiple add-ons.

##Usage

To initialize Flask-React, simply create a React instance and provide the Flask instance. Additional parameters:

  • index_template : Index page template to use instead of default one.
  • extensions : List of React extensions to use. Currently Material-UI, React-Bootstrap and Socket.IO are available.
  • jsx_folder: Source folder for JSX files. If provided, .jsx files are converted using Babel on initialization.
  • socket_io: Flask-SocketIO instance (socket.io is used).
from flask import Flask
from flask_react import React


app = Flask(__name__)
react = React(
   app,
   extensions=("material", "components"),
   jsx_folder='static/react/jsx/'
)


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

The React code goes into the static\react\js folder, or if you use JSX, the folder you provided at initialization. The App.js file must contain an App function that returns the contents of our application.

function App() {
  return React.createElement(
    "div",
    null,
    "Hello world!"
  );
}

If you use JSX, your App.jsx would look something like this:

function App() {
  return (
      <div>Hello world!</div>
  )
}

JSX files are converted using Babel CLI. In order for this to work, Node.JS needs to be installed.

Additional files that should be put in the static/react/ folder are:

  • favicon.ico
  • logo192.png, logo512.png
  • manifest.json

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

Flask-ReactJS-0.2.tar.gz (742.3 kB view details)

Uploaded Source

File details

Details for the file Flask-ReactJS-0.2.tar.gz.

File metadata

  • Download URL: Flask-ReactJS-0.2.tar.gz
  • Upload date:
  • Size: 742.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0

File hashes

Hashes for Flask-ReactJS-0.2.tar.gz
Algorithm Hash digest
SHA256 d9fdd4f81a33077df6c6201c3d9f39e9080d6bc74ccd9a160eedaf1e98a41c87
MD5 2ae780505b33795d73fa53325cee6a7a
BLAKE2b-256 51b034203cbb7e5accec78c17de88bd1f9016bdc2cad703afbb820af14778753

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