Skip to main content

Python to Javascript variable converter for the Masonite framework.

Project description

JSONite - The Python-to-Javascript variable transformer for Masonite

This package is intended to be used alongside the Masonite Framework and allows you to pass Python variables to your base template. If no data is passed to the Javascript object on a particular request then the object returns an empty string, else it returns a JSON object featuring the passed data.

Installation:

JSONite can be installed in your Masonite project's home directory with pip:

pip install JSONite

Setup

After installing JSONite, you'll need to add the JavascriptProvider to your application providers in config/providers.py.

# config/providers.py

# ...

from jsonite import JavascriptProvider

# ...

PROVIDERS = [
    # ...

    # Third Party Providers
    JavascriptProvider,

    # ...
]

After adding the provider, you'll need to add the JavascripMiddleware class to config/middleware.py.

# config/middleware.py

# ...

from jsonite import JavascriptMiddleware

# ...

HTTP_MIDDLEWARE = [
    # ...
    JavascriptMiddleware,
]

# ...

Lastly, you'll want to add the line that actually renders the Javascript in your base.html file. By default the function name will be javascript_data(), but you can customize this by setting the desired value to the environment variable JS_TEMPLATE_VAR in your .env file.

<!-- template/base.html -->
<DOCTYPE html>
<html>
    <!-- ... -->
<body>
    <!-- ... -->
    {{ javascript_data() }}
    <!-- ... -->
</body>
</html>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for JSONite, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size JSONite-0.0.3-py3-none-any.whl (5.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size JSONite-0.0.3.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page