Skip to content

nitely/python-react-v8

Repository files navigation

Python-React-V8

Build Status Coverage Status pypi licence

Thin wrapper around v8-cffi to render React views server-side.

Compatibility

What v8-cffi supports

Install

$ pip install python-react-v8

Usage

import react

from my_web_framework import render, orm, runserver


def index(request):
    """A naive implementation for a fake web-framework"""
    data = orm.query().only('name', 'age', 'location')
    react_ = react.React({
        'url': request.get_full_url(),
        'data': data})
    context = {
        'content': react_.render(),
        'data': react_.to_json(data)}

    return render('index.html', context)


if __name__ == '__main__':
    react.set_up() # Initialize V8 machinery
    react.utils.load_libs(['./bundle.js'])
    runserver(index)

Read the docs.

Examples

Build examples

$ make build-examples

Tests

$ make test

License

MIT