Skip to main content

Application variables passed from the server to the client.

Project description

django-var-js/README.rst
======
Var-js
======

Var-js is a simple Django application that allows communication
variables from the server to the client.

Installing
----------

pip install django-var-js

Requirements
-----------

JQuery

Quick start
-----------

1. Include the var-js URLconf in your project urls.py like this::

url(r'^', include('var_js.dj_var_js.urls')),

2. In the view.py::

from var_js.views import DjVarJs

def example(request):
#Values
variable = "To JavaScript"
dicc = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}

#Instance of class DjVarJs
pyvar = DjVarJs()

#Set values
pyvar.set("variable", variable , request)
pyvar.set("dicc_django", dicc, request)

return render_to_response('example.html', context_instance=RequestContext(request))

3. In the template::

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src='{{STATIC_URL}}js/var_js/djvarjs.js'></script>
<script src='{{STATIC_URL}}js/example/main.js'></script>
</head>
<body>
<h1>App Django-var-js</h1>
<label id="key_js"></label>
<br>
<label id="dict_js"></label>
<body>
</html>

4. In the file .js::

var valor = DjVarJs.getKey("variable");
$("#key_js").text(valor);

var arr = DjVarJs.getDict("dicc_django");
$("#dict_js").text("Clave1: " + arr['clave1'] + ", Clave2: " + arr['clave2'] + ", Clave3: " + arr['clave3']);

5. Visit http://127.0.0.1:8000/example/

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

django-var-js-1.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file django-var-js-1.1.tar.gz.

File metadata

File hashes

Hashes for django-var-js-1.1.tar.gz
Algorithm Hash digest
SHA256 4c11a8b9010f8775d3640a2b8b4f046a1f5faa487744d50b3fb15204ac7b39d6
MD5 12bb73f1e6d0ce8e07193467cefa6c2d
BLAKE2b-256 c971e4a2b94c2e23fe8acbbc1590bf086a97df16fa280f43cce6feb3c357b722

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