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.

Source Distribution

JSONite-0.0.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

JSONite-0.0.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file JSONite-0.0.2.tar.gz.

File metadata

  • Download URL: JSONite-0.0.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for JSONite-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5f56598b3ebba9a8d73d5aa3212caa94255c4e4011cc8b004f957f5da57b3e58
MD5 1986ab8450b6e00363ca55ca42c7499f
BLAKE2b-256 9a1f27e9e3e7284eae766181f6136bf116951c9bb79dbae1d00e6c4eade2840b

See more details on using hashes here.

File details

Details for the file JSONite-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: JSONite-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for JSONite-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 204a9b7ab438d2c5d4472379f4de2d96321429d50eec408535681def6434ebe5
MD5 76a7c6c99f68ab83d9797382a19af8fc
BLAKE2b-256 89b811bf0a1bf692cb6c664f32775d1738d9c20378a7ddfc0ffbcae803847a87

See more details on using hashes here.

Supported by

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